2016-01-22 120 views
18

我在我的main.js文件中的Vue-Resource中指定了一个根选项,但是当我执行请求时,它不使用根选项。我错过了什么?Vue资源根选项未使用?

下面的代码:

main.js:

Vue.http.options.root = 'http://api.domain.com/v1/' 

在一个部件:

ready: function() { 
    console.log(this.$http.options.root) // Correctly show 'http://api.domain.com/v1/' 

    this.$http.get('/members/', null, { // FAILS because it tries to load /members/ in the current domain 
     headers: {'auth-token': 'abcde'} 
    }).then(function (xhr) { 
     // process ... 
    }) 
} 

我在做什么错?

我使用Vue.js v1.0.15和Vue公司,资源V0.6.1

谢谢您的帮助。

回答

43

Ohoh这很棘手!

为了根本上加以考虑,则需要从URL中删除初始/

this.$http.get('/members/')成为this.$http.get('members/')

此外,您还需要去掉最后/根:

Vue.http.options.root = 'http://api.domain.com/v1/' 

成为

Vue.http.options.root = 'http://api.domain.com/v1' 

而且,它会工作!

+0

哈哈,谢谢。我也在努力为什么根不工作。 – GusDeCooL