Heim  >  Artikel  >  Backend-Entwicklung  >  请教一下,vue-resource 发送ajax请求始终为nill

请教一下,vue-resource 发送ajax请求始终为nill

WBOY
WBOYOriginal
2016-10-10 11:56:081284Durchsuche

请教一下,各位大神,
我在用vue-resource做ajax请求的时候,响应始终为null, 而JQuery请求的时候就能正常响应,请教一下这是怎么回事,

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

请教一下,vue-resource 发送ajax请求始终为nill

回复内容:

请教一下,各位大神,
我在用vue-resource做ajax请求的时候,响应始终为null, 而JQuery请求的时候就能正常响应,请教一下这是怎么回事,

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

请教一下,vue-resource 发送ajax请求始终为nill

Vue.http.options.emulateJSON = true

@阿发 谢啦,不过加上这句也没什么效果,,
刚看了下,它接收的是 Response { url="/a", ok=true, status=200, 更多...}这样一个对象。
我用这样的形式,可以正常访问了

<code>`this.$http.get('/a').then(({data})=>{
                    vm.list = data;
                    console.log(data);
                },(data)=>{
                    console.log(data);
                })`</code>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn