26

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

这是代码:

主.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-Resource v0.6.1

谢谢您的帮助。

4

1 回答 1

59

哦,这很棘手!

为了考虑到 root ,您需要/从 url 中删除首字母:

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

此外,您需要删除/root 中的最后一个:

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

变成

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

有了它,它就会起作用!

于 2016-01-22T13:02:55.840 回答