uniApp 监听globalData

App.vue

globalData:{
        infoType:''
    },

methods:{
         watch:function(method,istr){
                var obj=this.globalData
                console.log(obj)
                Object.defineProperty(obj,istr,{
                configurable:true,
                enumerable:true,
                set:function(value){
                    this._consumerGoodsStatus=value
                    method(value)
                },
                get:function(value){
                            return this._consumerGoodsStatus
                        }
                    })
                }
    },

页面调用

getApp().watch(this.getcartcount,'infoType')
    getcartcount(val){
                console.log('输出变化的值',val)
            },

 

posted @ 2022-03-02 11:55  风一样的猿  阅读(1427)  评论(0)    收藏  举报