vue.js 2.0中props数据绑定的warning

[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: "products"

因为products是props中的属性,不能在子组件中赋值
子组件的函数中,写了语句this.products = res.data.objects;,因而报错。

在Vue2中组件的props的数据流动改为了只能单向流动,即只能由组件外(调用组件方)通过组件的DOM属性attribute传递props给组件内,组件内只能被动接收组件外传递过来的数据,并且在组件内,不能修改由外层传来的props数据。

更加详细的信息参照vue官方文档的单向数据流

猜你喜欢

转载自blog.csdn.net/love_parents/article/details/81941728
今日推荐