手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2021年10月1日的文章

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

 InertiaJS和VueNestable共用时,遇到的Avoid mutating a prop directly since the value will be overwritten whenever the parent.

因为在使用InertiaJS时,所有的变量都是通过props传递进去的。比如分类的数据。这时候用vue-nestable,就会出现上面的错误:[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: xxxx

因为xxxx变量是props传过来的。因此不能在子组件再通过组件来修改xxxx变量。要偷懒直接在data变量中定义一个中间变量,这时候就方便了。

data(){
    return {
        yyyy: this.xxxx
    }
}

然后vue-nestable的v-model可以直接用this.yyyy,报错信息解除。

-----

这个问题主要是出在inertiaJS上。毕竟其他完整的页面demo,变量都是当前页直接给出来的,所以就不会出错了,但遇到问题还是要看本质,才知道怎么改