vue.js - Vue 深度手表道具
问题描述
在我的组件中,我有一个计算属性
members() {
return (this.club.properties || []).map(property => {
const user = Object.assign({}, property.user, property, { user: undefined })
return user
})
},
这个计算属性是作为另一个组件上的 v-bind 给出的
<MyComponent :members="members" :club="club"/>
当我添加新属性时,MyComponent 组件会显示所有成员
this.club.properties.push(someProperty)
MyComponent 没有被重新渲染我必须刷新页面才能渲染新属性。
解决方案
您需要进行深度复制以使 Vue 具有反应性
this.club.properties.push(someProperty)
this.club = JSON.parse(JSON.stringify(this.club))
这是常见的Vue 反应性问题
推荐阅读
- php - 向 Laravel 项目添加多个中间件
- git - “git clone user@server/my-repo.git”和“git clone git://user@server/my-repo.git”有什么区别
- python - 将元素添加到指定数据框行中的列表
- javascript - Javascript 代理和传播语法,结合 console.log
- sql-server - 递归 CTE 层次结构中的双行
- arrays - 压缩最近邻算法 - 返回数组的混淆
- google-apps-script - 谷歌工作表命名范围在工作表之间不一致
- c# - 单击该项目后显示数据库中的特定数据
- go - 谷歌云 SQL 的 GoLang SDK
- vb.net - 按下外部应用程序的特定按钮,没有十六进制句柄的名称