Laravel 单击事件url中的axios get请求链接错误
我试图在laravel的axios vue.js中获取单击事件的id,但在控制台中获取的url错误Laravel 单击事件url中的axios get请求链接错误,laravel,vue.js,axios,Laravel,Vue.js,Axios,我试图在laravel的axios vue.js中获取单击事件的id,但在控制台中获取的url错误 http://{mylink}/messages/getMessages1 而不是 http://{mylink}/messages/getMessages/1 我希望输出作为第二个url 我在file.js中的方法如下所示: methods:{ messages:function(id){ let vm = this; this.$http
http://{mylink}/messages/getMessages1
而不是
http://{mylink}/messages/getMessages/1
我希望输出作为第二个url
我在file.js中的方法如下所示:
methods:{
messages:function(id){
let vm = this;
this.$http
.get('messages/getMessages' + id)
.then(response => {
console.log(response.data);
vm.privateMsgs = response.data;
})
.catch(function (error) {
console.log(error.response);
});
}
Route::get('/messages/getMessages/{id}','Messages@getuser');
public function getuser($id){
echo $id;
}
路线如下所示:
methods:{
messages:function(id){
let vm = this;
this.$http
.get('messages/getMessages' + id)
.then(response => {
console.log(response.data);
vm.privateMsgs = response.data;
})
.catch(function (error) {
console.log(error.response);
});
}
Route::get('/messages/getMessages/{id}','Messages@getuser');
public function getuser($id){
echo $id;
}
控制器如下所示:
methods:{
messages:function(id){
let vm = this;
this.$http
.get('messages/getMessages' + id)
.then(response => {
console.log(response.data);
vm.privateMsgs = response.data;
})
.catch(function (error) {
console.log(error.response);
});
}
Route::get('/messages/getMessages/{id}','Messages@getuser');
public function getuser($id){
echo $id;
}
请指导我更正此问题。您的axios请求中缺少斜杠。应该是:
.get('/messages/getMessages/' + id)
我检查过了,代码运行正常
messages:function(id){
var self = this;
this.$http.get('/messages/getMessages/' + id)
.then(response => {
console.log(response.data);
this.privateMsgs = response.data;
})
.catch(function (error) {
console.log(error.response);
});
}
对错误没有影响