When I wrote the code today, I found that the data has changed, but the view has not been updated.
Baidu found that vm.items[indexOfItem] = newValue is undetectable. I
wrote a page to verify that it is indeed undetectable. The
output is
then found, the view To respond to changes in the array,
push()
pop()
shift()
unshift()
splice()
sort()
reverse()
and set
<template>
<!-- 验证vm.items[indexOfItem] = newValue是否真的无效 -->
<div>
<div>{
{
aa}}</div>
<ul>
<li v-for="item in list"
:key="item.id">
{
{
item.text}}
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'testWuXiao',
data () {
return {
aa: 'abcdefg',
list: [
{
id: '1', text: 'A'
},
{
id: '2', text: 'A'
}
]
}
},
mounted () {
this.aa = 'hijklmn'
for (let i = 0; i < this.list.length; i++) {
// this.list[i].text = 'B'
this.$set(this.list[i], 'text', 'B')
}
}
}
</script>
<style scope lang="less">
</style>