Mardanjan / Blog

学习笔记(在issues里),一些小demo的源码在这里,demo在线地址会持续更新
1 stars 0 forks source link

Vue.js watch 监听对象的内部属性变化 #3

Open Mardanjan opened 4 years ago

Mardanjan commented 4 years ago

普通的watch属性不能监听对象内部属性的变化,需要加depp:true, 也可以单独监听对象里的某个属性,, https://blog.csdn.net/qq_33878858/article/details/93886574 这个文章可以

watch: {
        item:{
            handler(val){
                console.log('val',val)
                if (this.item.product_detail) {
                    if (this.item.product_detail.length > 2) {
                        this.head_item = this.item.product_detail.slice(0,2)
                        this.body_item = this.item.product_detail.slice(2)
                        this.isShowMore =  true
                        return
                    } else if (this.item.product_detail.length <= 2) {
                        this.head_item = this.item.product_detail.slice(0,2)
                        this.isShowMore =  false
                    }

                }else if (!this.item.product_detail) {
                    this.isShowMore = false
                    this.head_item = this.item.product_detail
                }
            },
            deep:true
        }
    },