让vue用于小程序setData方法

setData:function(obj){
                let that = this;
                let keys = [];
                let val,data;
                Object.keys(obj).forEach(function(key){
                    keys = key.split('.');
                    val = obj[key];
                    data = that.$data;
                    keys.forEach(function(key2,index){
                        if(index+1 == keys.length){
                            that.$set(data,key2,val);
                        }else{
                            if(!data[key2]){
                                that.$set(data,key2,{});
                            }
                        }
                        data = data[key2];
                    })
                });
            }

  

posted @ 2019-08-10 17:17  惠鹏曦  阅读(5029)  评论(0编辑  收藏  举报