Axios在单击事件的URL中获取请求链接错误



我正在尝试在axios vue.js in laravel中获得单击事件的ID,但我在控制台中遇到了URL。

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;
   }

请指导我正确。

您缺少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);
        });
}

最新更新