Subscribe on changes!

重新使用 `reactive` 赋值 视图不会更新

avatar
Nov 26th 2020

Version

3.0.2

Reproduction link

https://codepen.io/lf171314/pen/GRjRoWE?editors=1111

Steps to reproduce

  • 点击删除按钮,视图不会更新,但是数据改变了
  • 更改注释内容,点击删除按钮后,视图会更新

What is expected?

重新赋值可以更新视图

What is actually happening?

视图不会更新

avatar
Nov 26th 2020

This is expected, you are overwriting the variable instead of changing it's content. Use a ref instead:

let list = Vue.ref([1, 2, 3])
    const handleDelete = item => {
      // This is work
      // const index = list.value.indexOf(item)
      // if (index !== -1) list.value.splice(index, 1) 
      list.value = list.value.filter(i => item !== i)
    }

Please, next time consider using the forum, the Discord server or StackOverflow for questions first. But feel free to come back and open an issue if it turns out to be a bug 🙂