-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support v-if multiple conditions #4271
Changes from all commits
89bd64b
a07cdbb
12f15d3
4102de3
687fd2b
2148b5e
f83424c
3e5cf2a
e7a4aac
47eb2b9
0644a7a
b1f0169
0b0fa19
85f5ee5
e2c898d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ declare type ModuleOptions = { | |
} | ||
|
||
declare type ASTModifiers = { [key: string]: boolean } | ||
declare type ASTIfConditions = Array<{ exp: ?string; block: ASTElement }> | ||
|
||
declare type ASTElementHandler = { | ||
value: string; | ||
|
@@ -95,8 +96,9 @@ declare type ASTElement = { | |
|
||
if?: string; | ||
ifProcessed?: boolean; | ||
elseif?: string; | ||
else?: true; | ||
elseBlock?: ASTElement; | ||
conditions?: ASTIfConditions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this |
||
|
||
for?: string; | ||
forProcessed?: boolean; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,55 @@ describe('Directive v-if', () => { | |
}).then(done) | ||
}) | ||
|
||
it('should work well with v-elseif', done => { | ||
const vm = new Vue({ | ||
template: ` | ||
<div> | ||
<span v-if="foo">hello</span> | ||
<span v-elseif="bar">elseif</span> | ||
<span v-else>bye</span> | ||
</div> | ||
`, | ||
data: { foo: true, bar: false } | ||
}).$mount() | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>hello</span>') | ||
vm.foo = false | ||
waitForUpdate(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the waitForUpdate magic |
||
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>') | ||
vm.bar = true | ||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>elseif</span>') | ||
vm.bar = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it wants a then chaining, + expect(vm.$el.innerHTML.trim()).toBe('<span>elseif</span>')
+ vm.bar = false should return a promise, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fnlctrl help wanted XD |
||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>') | ||
vm.foo = true | ||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>hello</span>') | ||
vm.foo = false | ||
vm.bar = {} | ||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>elseif</span>') | ||
vm.bar = 0 | ||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>') | ||
vm.bar = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would it be necessary for so many kind of |
||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>elseif</span>') | ||
vm.bar = null | ||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>') | ||
vm.bar = '0' | ||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>elseif</span>') | ||
vm.bar = undefined | ||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>') | ||
vm.bar = 1 | ||
}).then(() => { | ||
expect(vm.$el.innerHTML.trim()).toBe('<span>elseif</span>') | ||
}).then(done) | ||
}) | ||
|
||
it('should work well with v-for', done => { | ||
const vm = new Vue({ | ||
template: ` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this doing