【发布时间】:2016-11-02 10:44:20
【问题描述】:
我创建了两个dynamic 组件。现在,使用events: $emit/$on 我需要的是触发组件的“logThat(someObj)”方法 - 两个传递参数,正如您在这个小提琴中看到的那样:
Vue.component('component-one', {
template: '#template-a',
methods: {
onClick() {
const someObj = {
foo: "foo",
bar: "bar"
}
vm.$emit('selected', someObj)
vm.currentView ='component-two';
}
}
});
//Any hint??
/*vm.$on('selected', (someObj) => {
this.logThat(someObj)
})*/
Vue.component('component-two', {
template: '#template-b',
methods: {
onClick() {
vm.currentView ='component-one';
},
logThat(someObj) {
console.log(someObj);
}
}
});
https://jsfiddle.net/wanxe/yuh71e1o/
如果有人对如何处理这个问题有任何建议,我们将不胜感激:)
【问题讨论】:
标签: javascript vue.js vue-component