vue 使用过程中遇到的问题

vue 使用过程中遇到的问题[待整理]

observe data 数据不会随props数据象变化

Vue中props的数据不允许修改,故而采用新变量赋值的方式存储。但会引发一个问题props的数据已经更改,data这得未改

  • 使用Computed

    1
    2
    3
    4
    5
    6
    7
    8
    {
    props:['data1']
    computed:{
    test(){
    return this.data1
    }
    }
    }
  • data + watch

1
2
3
4
5
6
7
8
9
10
11
12
13
{
props:['data1']
data(){
return{
test:this.data1
}
}
watch:{
data1(){
this.test = this.data1
}
}
}

动态增加state数据,获取state数据

在生命中周期渲染中可以发现只有在created状态之前声明的状态才能有双向绑定监听的效果。

1
2
3
4
5
6
7
8
9
10
{
data:{
list:null //标记
},
methods:{
modifyState(state){
this.list = Object.assign({}, state)
}
}
}

1
2
3
4
5
6
7
8
9
10
function proxy (target, sourceKey, key) {
sharedPropertyDefinition.get = function proxyGetter () {
return this[sourceKey][key]
};
sharedPropertyDefinition.set = function proxySetter (val) {
this[sourceKey][key] = val;
};
Object.defineProperty(target, key, sharedPropertyDefinition);
}

Object.defineProperty ,vue数据观察实现的方式

vue 使用过程中遇到的问题[已整理]