search

Home  >  Q&A  >  body text

javascript - vue's communication $on modification of the original component data problem

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.

阿神阿神2826 days ago534

reply all(3)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:16:05

    ..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());
        }

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-19 10:16:05

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

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:16:05

    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

    reply
    0
  • Cancelreply