Avoid mutating a prop directly since the value will be overwritten whenever

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders

出现错误的原因在于:

父组件通过props传值给子组件,子组件改变props的属性值报错问题

props:['projects','num','project', 'cur_type','customer_id', 'user_id']
改变了projects
// this.projects = this.projects.filter(item => {
          //     return item.id !== this.project
          // })

父子组件中的数据流是单向的, 同时也给出了子组件操作数据时的解决方法。

computed:{
        filter_project(){
            return this.projects.filter(item => {
                return item.id !== this.project
          })
        },
    }

可以通过计算属性的方式实现对数据的修改。

猜你喜欢

转载自blog.csdn.net/qq_37304462/article/details/111306918