Home  >  Article  >  Backend Development  >  Please tell me, the ajax request sent by vue-resource is always nill.

Please tell me, the ajax request sent by vue-resource is always nill.

WBOY
WBOYOriginal
2016-10-10 11:56:081315browse

Excuse me, dear masters,
When I use vue-resource to make ajax requests, the response is always null, but JQuery can respond normally when making requests. Please tell me what is going on,

<code>created:function () {
                var vm = this;
                $.get('/a', function (data) {
                    vm.list = data;
                });   //JQuery请求

               this.$http.get('/a', function (data) {
                   vm.list = data;
               }); //Vue-resource请求
            },</code>

Please tell me, the ajax request sent by vue-resource is always nill.

Reply content:

Excuse me, dear masters,
When I use vue-resource to make ajax requests, the response is always null, but JQuery can respond normally when making requests. Please tell me what is going on,

<code>created:function () {
                var vm = this;
                $.get('/a', function (data) {
                    vm.list = data;
                });   //JQuery请求

               this.$http.get('/a', function (data) {
                   vm.list = data;
               }); //Vue-resource请求
            },</code>

Please tell me, the ajax request sent by vue-resource is always nill.

Vue.http.options.emulateJSON = true

@阿发 Thanks, but adding this sentence has no effect,
Just checked it, it received Response { url="/a", ok=true, status=200, more... } Such an object.
I use this form and can access it normally

<code>`this.$http.get('/a').then(({data})=>{
                    vm.list = data;
                    console.log(data);
                },(data)=>{
                    console.log(data);
                })`</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn