在Vuejs / Larvel论坛中,显示问题及其答复时出现以下错误:
POST http://127.0.0.1:8000/broadcasting/auth 405 (Method Not Allowed)
如果我从列出注释的组件中删除Echo.private方法,则错误消失。但是,我看不到Echo ...方法是不正确的,也不知道要看什么。
相关的代码(我希望是)是:
bootstrap.js
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'myKey',
wsHost: window.location.hostname,
wsPort: 6001,
disableStats: true,
auth:{
headers:{
Authorization: JWTtoken
}
}
});
channels.php
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
Broadcast::channel('likeChannel', function () {
return true;
});
replies.vue
<template>
<div>
<p v-if="comments>0"><em>{{$t('Comments')}}</em></p>
<reply
v-for="(r,index) in content"
:key="r.id"
:index=index
v-if="question.replies"
:data="r"
></reply>
</div>
</template>
<script>
import Reply from './Reply';
import { eventBus } from '../../app';
export default {
name: "Replies",
props: ['question'],
components: {Reply},
data(){
return {
content:this.question.replies,
comments:this.question.replies.length,
}
},
created(){
this.listen();
},
methods: {
listen(){
console.log('userID='+this.UserID)
Echo.private('App.User.' + this.UserID)
.notification((notification) => {
console.log('Replies 36; Notification type: '+ notification.type);
this.content.unshift(notification.reply)
});
eventBus.$on('replyCreated',(reply)=>{
this.content.unshift(reply) //unshift adds item to top of array
});
eventBus.$on('deleteReply',(index) => {
axios.delete(`api/question/${this.question.slug}/reply/${this.content[index].id}`)
.then(res => {
this.content.splice(index,1);
}
)
});
},
},
computed: {
UserID: function () {
var tk = localStorage.getItem('token');
var payload = tk.split('.')[1];
var pl = JSON.parse(atob(payload));
return pl.sub;
},
}
}
</script>
<style scoped>
</style>
注释掉所有Echo.private材料可消除错误;仅注释掉.notification部分不会产生相同的效果,表明它不是'notification'的内容。
很明显,我向世人展示了自己是陌生的,迷失在太空中。也许我看到的是其他地方出现问题的结果-但我茫然在哪里寻找其他地方。
谢谢, 汤姆