vue中组件有ajax获得数据用watch获取不正常改用computed 解决一例
编辑时间:2020-02-06 作者:金满斗 浏览量:1478 来源:原创

vue真的太爽了。早用早爽。

很棒的就是组件设计思想,然后就是watch,computed,怎么爽怎么开心。

我一般组件的数据由父组件获取,组件里用watch里监听。


这次用到个数据是个对象,对象里有包含了数组,watch不管用了,怎么办呢,要对象里需要的单独拿出来用computed  计算监听,解决了。

props:{
			GoodsLogLst:{
				type:Object,
				default:()=>{return {}}
			},
		},
		watch:{ //监听器,这个不起作用了,用下面的computed拆分计算可以
			GoodsLogLst(e){
				console.log(e);
				console.log('来啦老对');
				this.lstData = newddata ;
			}
		},
		computed:{
			sales_details() {
			  return this.GoodsLogLst.sales_details;
			},
			order_no:{
				//读回调
				get(){
					return this.GoodsLogLst.order_no ;
				}
			}
		},

反正能跑就行啦,记录下。


来说两句吧