【发布时间】:2017-09-15 09:01:10
【问题描述】:
我正在尝试使用 Vue.js,但遇到了问题。我正在学习 Laracasts 的教程,但我的 v-for 不起作用。
HTML:
<div id="root">
<ul>
<li v-for="name in names" v-text="name"></li>
</ul>
<input type="text" v-model="newName">
<button @click="addName">Add Name</button>
</div>
JS:
new Vue({
el: '#root',
data: {
newName: '',
names: ['John', 'Mike']
}
methods: {
addName() {
this.names.push(this.newName);
this.newName = '';
}
}
})
小提琴:https://jsfiddle.net/4pb1f4uq/
如果有帮助,请链接到带有剧集的 Laracast: https://laracasts.com/series/learn-vue-2-step-by-step/episodes/4?autoplay=true
【问题讨论】:
-
如果您在编译器甚至控制台中读取输出,可能会有所帮助。它会显示您在定义数据后忘记放置逗号。