没有使用Vue资源根选项?

Cyr*_* N. 24 vue.js vue-resource

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

这是代码:

main.js:

Vue.http.options.root = 'http://api.domain.com/v1/'
Run Code Online (Sandbox Code Playgroud)

在一个组件中:

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 ...
    })
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么 ?

我正在使用Vue.js v1.0.15和Vue-Resource v0.6.1

谢谢您的帮助.

Cyr*_* N. 58

哦,这很棘手!

为了考虑root,您需要/从url中删除initial :

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

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

Vue.http.options.root = 'http://api.domain.com/v1/'
Run Code Online (Sandbox Code Playgroud)

Vue.http.options.root = 'http://api.domain.com/v1'
Run Code Online (Sandbox Code Playgroud)

有了它,它会工作!