javascript - 如何使用vue中的$on更新data数据并渲染?
巴扎黑
巴扎黑 2017-04-10 18:09:21
[JavaScript讨论组]

组件间简单通信使用空的实例:

var app = new Vue();
然后组件1触发app.$emit:

methods: {

linkToDoing: function () {
    this.isToDoing = true;
    this.store.isToDoing = this.isToDoing;
    this.store.selectIndex = 0;
    app.$emit('store', this.store);
},

} 组件2监听触发的事件app.$on:

created: function () {

app.$on('store', function (data) {
    this.title = data.arrTitle[data.selectIndex];
    console.log('监听到了', this.title);
    this.store = data;
});

}
最后发现能够监听到更新的数据,但是数据未渲染,请问这个如何解决?

巴扎黑
巴扎黑

全部回复(1)
怪我咯

把 this 改为 app 应该就可以了吧

app.$on('store', function (data) {
    app.title = data.arrTitle[data.selectIndex];
    console.log('监听到了', app.title);
    app.store = data;
});
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号