【发布时间】:2020-09-16 07:27:27
【问题描述】:
我需要从邮件列表标签运行 refreshMailList 函数,从邮件列表组件中捕获点击事件。
我有这个带有这个组件的 vue 实例:
Vue.component('mail-list', {
props: ['inboxmail'],
template:
`
<div>
<h4>{{inboxmail}}</h4>
<button>Refresh</button>
</div>
`
});
//Creating the Vue object.
let options = {
el: "#app",
data: {
pollingId: null,
inbox: ''
},
created: function() {
this.refreshMailList()
},
methods:{
refreshMailList: function(){
fetch('/inbox')
.then(response => response.json())
.then(aJson => {
this.inbox = aJson;
})
},
} //end methods
} //end options
//ViewModel (vm)
let vm = new Vue(options);
我有这个 index.html:
<div id="app">
<mail-list v-bind:inboxmail="inbox" @refresh='refreshMailList'></mail-list>
</div>
【问题讨论】:
标签: javascript vue.js events components emit