<body>
<div id="root">
<ul>
<li v-for="(p,index) in persons" :key="index">
{{p}}
</li>
</ul>
</div>
<script>
const vm = new Vue({
el: '#root',
data: {
persons: []
},
mounted() {
this.persons = [];
this.persons[0] = '张三'
this.persons[1] = '李四'
}
});
</script>
</body>
有了“this.persons = [];”这句页面就能显示出张三、李四,注释掉这句就不行,为什么?
this.persons = []; 并不属于push、pop、shift、unshift、splice、sort、reverse这七个方法之一
本回答被网友采纳