vue动态给data里的变量赋值

data(){
    return{
        a:null,
        b:null,
        c:null
    }
},
created:{
    this.xx('a'),
    this.xx('b'),
    this.xx('c'),
},
methods:{
    xx(arg){
       这里的arg分别会传来'a','b','c'
       我在这里怎么可以变成
       this.a="值"
       this.b="值"
       this.c="值"
    }    
}
阅读 12.6k
1 个回答

直接在

created

方法中给对应的属性赋值就可以了,

或者这样写

data(){
// 这个值可以
    let  a = '张三'
    let b  = 'lisi'
    let c  = 'lisi'
    
    return{
        a,
        b,
        c
    }
},
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题