2016-01-22 61 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