今天我被困在Vue的圈里了。我知道循环的基本原理,如果以前问过这些问题,我会四处看看。但他们都没解决我的问题。
代码循环:
<ul>
<li :v-for="todo in todos">
{{ todo.text }}
</li>
</ul>代码对象:
todos: [
{ text: "Subscibe to Renatello.com newsletter", done: true },
{ text: "Learn Vue", done: false },
{ text: "Build awesome projects", done: false }
]我得到的错误是:无法读取未定义的属性“text”
希望这里有个人能帮我。
解决方案:
todo中的:v-for: as v-for="(todo,index)“,”具有:key=“索引
提前谢谢。
发布于 2021-03-29 08:41:57
在v-for之前移除冒号。
发布于 2021-03-29 08:43:00
我对Vue不是很强,但我不认为你想要: on :v-for,只想要v-for
const app = new Vue({
el: '#app',
data: {
todos: [
{
text: "Subscibe to Renatello.com newsletter",
done: true
},
{
text: "Learn Vue",
done: false
},
{
text: "Build awesome projects",
done: false
}
]
}
})
setTimeout(() => {
app.todos = [
...app.todos,
{
text: "more",
done: false
}
];
}, 1000);<div id="app">
<ul>
<li v-for="todo in todos">
{{ todo.text }}
</li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
https://stackoverflow.com/questions/66850946
复制相似问题