Vue.js 深表道具

Vue.js 深表道具,vue.js,Vue.js,在我的组件中,我有一个计算属性 members() { return (this.club.properties || []).map(property => { const user = Object.assign({}, property.user, property, { user: undefined }) return user }) }, 此计算属性作为另一个组件上的v绑定提供 <MyComponent :members="members" :c

在我的组件中,我有一个计算属性

members() {
  return (this.club.properties || []).map(property => {
    const user = Object.assign({}, property.user, property, { user: undefined })
    return user
  })
},
此计算属性作为另一个组件上的v绑定提供

<MyComponent :members="members" :club="club"/>

MyComponent未重新提交。我必须刷新页面才能呈现新属性。

您需要进行深度复制才能使Vue反应

this.club.properties.push(someProperty)
this.club = JSON.parse(JSON.stringify(this.club))

这是很常见的

或者,您可以使用
Vue.set(object,propertyName,value)
一次更新一个俱乐部属性,使其具有响应性


请参见

是的,我也认为这是解决方案,因为在
俱乐部
对象中,
属性
键指向内存中的另一个位置,因此,我认为您需要使
this.club
意识到更改。vue不允许我这样做,因为club是一个道具。然后您需要向父元素发出事件,并在父元素中更改
this.club
this.club.properties.push(someProperty)
this.club = JSON.parse(JSON.stringify(this.club))