javascript - vue's communication $on modification of the original component data problem
阿神
阿神 2017-05-19 10:14:05
0
3
532

export default {
name: 'login',
data () {

return {
  navcard:['首页','工作室简介','人员分工','项目计划','重点故障分析','技能创新','带徒传技','技能培训','技术交流论坛'],
  msg:'主页'
}
},

created:function(){

  var self=this

  bus.$on('login_loginstae',function(a){
       console.log(a);
       self.msg=a;
  })
 

}
}
bus.$on received a, console.log (a) shows that the value of a is fine, but self.msg=a does not work. The msg on the page will not change.

阿神
阿神

闭关修行中......

reply all(3)
过去多啦不再A梦

..To be honest.
I tested
It works...

created: function() {
            this.demo = 'demoxx123xx';
            var self = this;
            bus.$on('test', function(msg) {
                self.demo = msg
            })
        }
test() {
      bus.$emit('test', new Date());
    }
世界只因有你

It should be that create has not been mounted yet, try mounted

过去多啦不再A梦

You may not believe it. After commenting on yours, I tried it again and it worked. It feels like the node cache is a bit powerful and it didn’t get better in the afternoon

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template