我通过父组件传递给子组件一个数组couponlist,然后在子组件里声明了这个couponList 并通过计算属性对它进行了处理 但是我这里计算属性coupons居然是undefined,倒是在mounted里边通过打印this.couponList能获取到处理之后的数组 这就奇怪了 coupons怎么会是undefined呢
export default {
props: ['couponList'],
created() {
},
computed: {
coupons() {
return this.couponList.forEach((item) => {
item.createTime = formatDate(item.createTime,0)
item.endTime = formatDate(item.endTime,0)
})
}
},
mounted() {
console.log(this.couponList)
}
}
返回 foreach 了,且最好不要在子组件里修改父组件的变量
或者支持对象展开的话