获取错误POST http://127.0.0.1:8000/chat/getChat/20 405(方法不允许)
当我手动访问此网址时,它会向我显示包含登录用户和朋友之间数据的聊天模型,但是在axios中它会给出错误。
我的CODE出了什么问题?
JS:
const app = new Vue({
el: '#app',
data: {
chats: [],
chat: 'Hello Universe'
},
created() {
const userId = $('meta[name="userId"]').attr('content');
const friendId = $('meta[name="friendId"]').attr('content');
if (friendId != undefined) {
axios.post('/chat/getChat/' + friendId)
.then(function (response) {
this.chats = response.data;
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
}
});
Component:
<template>
<div class="panel-block">
component
</div>
</template>
<script>
export default {
props: ['chats'],
mounted() {
console.log('Component mounted.')
}
}
</script>
答案 0 :(得分:0)
const app = new Vue({
el: '#app',
data: {
chats: [],
chat: 'Hello Universe'
},
created() {
const userId = $('meta[name="userId"]').attr('content');
const friendId = $('meta[name="friendId"]').attr('content');
if (friendId != undefined) {
axios.Get('/chat/getChat/' + friendId)
.then(function (response) {
this.chats = response.data;
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
}
});
组件: 零件
尝试并使用Get
查看...答案 1 :(得分:0)
路由:: get('/ chat / getChat / {id}','ChatController @ getChat') - &gt;中间件('auth');
应该是
路由::帖子('/ chat / getChat / {id}','ChatController @ getChat') - &gt;中间件('auth');
导致axios在后端使用post方法请求路由是get,因此它不允许请求,即405(Method Not Allowed)