【发布时间】:2018-05-04 22:23:33
【问题描述】:
我在按照本教程使用 Pusher 和 Vue.js 在 Laravel 中实现简单聊天时遇到问题:link tutorial。
首先,我在导航栏中的路线是这条:
我的 web.php 文件包含以下路径:
Auth::routes();
Route::get('/', 'TweetController@index');
Route::get('tweets', 'TweetController@showTweets')->middleware('auth');
Route::post('tweets', 'TweetController@sentTweet')->middleware('auth');
我在 assets/js 中提出请求的 app.js 文件是这个:
const app = new Vue({
el: '#app',
data: {
tweets: []
},
created() {
this.showTweets();
Echo.private('chat')
.listen('TweetSentEvent', (e) => {
this.tweets.push({
tweet: e.tweet.tweet,
user: e.user
});
});
},
methods: {
showTweets() {
axios.get('/tweets').then(response => {
this.tweets = response.data;
});
},
addTweet(tweet) {
this.tweets.push(tweet);
axios.post('/tweets', qs.stringify(tweet)).then(response => {
console.log(response.data);
});
}
}
});
如您所见,我使用 Axios 发送请求。
一切看起来都很好,但是 GET 和 POST 请求不起作用。控制台检查器中的错误显示如下:
GET http://localhost/tweets 404(未找到)
未捕获(承诺中)错误:请求失败,状态码为 404 在 createError (app.js:13931) 结算时 (app.js:35401) 在 XMLHttpRequest.handleLoad (app.js:13805)
获取https://stats.pusher.com/timeline/v2/jsonp/1session=Njg3NjQyNDY5NT....MjY1fV0%3D0() 发布http://localhost/broadcasting/auth 404(未找到)
当我尝试发帖时:
POST http://localhost/tweets 404(未找到)
get/post 应该朝着这个方向:
但我不知道发生了什么。有什么建议吗?我绝望了:D。 提前致谢!
【问题讨论】:
标签: php laravel vue.js axios pusher