我在我的 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
感谢您的帮助。
最佳答案
哦,这很棘手!
为了考虑到 root,您需要从 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'
有了它,它就会起作用!
关于vue.js - 未使用 Vue 资源根选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34945562/