let app = Vue.createApp({
template: `
<div>
<ul>
<li
v-for="todo of todoList" :key="todo.id"
v-if="!todo.completed"
>
{{ todo.content }}
</li>
</ul>
</div>
`,
data() {
return {
todoList: [
{
id: 1,
content: 'CONTENT 1',
completed: true
},
{
id: 2,
content: 'CONTENT 2',
completed: false
},
{
id: 3,
content: 'CONTENT 3',
completed: true
}
]
}
}
}).mount('#app');
todo
这个属性todo
我们其实可以通过查看 render 函数的处理方式来佐证优先级:
let app = Vue.createApp({
template: `
<ul>
<li
v-for="todo of todoList" :key="todo.id"
v-if="todoList.length !== 0"
>
{{ todo.content }}</li>
</ul>
`,
data() {
return {
todoList: [...]
}
}
}).mount('#app');
console.log(app.$options.render);
我们单击这条打印(单击函数名 render):
我们会发现解析之后是:
todoList.length !== 0