在 Laravel-8 中使用 Vue(SPA)我正在尝试使用事件并从组件中获取一些数据,但是数据没有被获取,我得到的错误是:- 404异常“Symfony\Component\HttpKernel\Exception\NotFoundHttpException”这是我用来发送DisplayMessages事件请求的Contacts.vue:-<template> <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="card"> <div class="card-header">Contacts List</div> <div class="card-body"> <ul v-for="contact in contacts" :key="contact.id" > <li> <button @click="displayMesages(contact.id)"> {{contact.name}} </button> </li> </ul> </div> </div> </div> </div> </div></template><script> export default { data(){ return { contacts: [] } }, mounted() { axios.get('/api/contacts-list') .then(response => this.contacts = response.data) }, methods: { displayMesages(id){ console.log(id); DisplayMessages.$emit('refresh', id); } } }</script>这是接收请求的DisplayMessages.vue :-<template> <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="card"> <div class="card-header">Display Messages</div> <div class="card-body"> <h2 v-for="message in messages">{{message.message}}</h2> </div> </div> </div> </div> </div></template>
2 回答
肥皂起泡泡
TA贡献1829条经验 获得超6个赞
axios 路由中的DisplayMessages.vue中存在输入错误:-
mounted() {
DisplayMessages.$on('refresh', (id)=>{
axios.get('/api/display-message/'+ id).then(response => this.messages = response.data) //It should be '/api/display-messages/`
});
}
添加回答
举报
0/150
提交
取消