我正在订阅状态频道并收到以下错误:
XHR加载失败:POST“ http://127.0.0.1:8000/broadcasting/auth”。
仅在重新加载页面(检查控制台)后,POST
请求才会成功。如何使其(POST调用)通过而无需重新加载页面?
<tr v-for="user in users">
<td>{{user.name}}</td>
<td>{{user.ip}}</td>
</tr>
data() {
return {
users:[]
}
},
mounted() {
window.Echo.join('privateChannel')
.here(users => (this.users = users))
.joining(user => (this.users.push(user)))
.leaving(user => (this.users = this.users.filter(u => (u.id
!==user.id)))
);
this.fetchData()
},
methods: {
fetchData(){
axios
.get('api/users')
.then(res => (this.users= res.data))
.catch(err => console.log(err));
},
}
}
答案 0 :(得分:0)
您使用的是get
而不是post
尝试一下-
fetchData(){
axios
.post('api/users')
.then(res => (this.users= res.data))
.catch(err => console.log(err));