Vue Resource root options not used?
I specify a root options in my Vue-Resource in my main.js file, but when I do the request, it does not use the root options. What am I missing ?
Here's the code :
main.js:
Vue.http.options.root = 'http://api.domain.com/v1/'
In a component :
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 ...
})
}
What am I doing wrong ?
I'm using Vue.js v1.0.15 and Vue-Resource v0.6.1
Thank you for your help.
answer:
Ohoh this is tricky !
In order for root to be taken into consideration, you need to remove the initial / from the url :
this.$http.get('/members/') becomes this.$http.get('members/')
Also, you need to remove the last / in the root :
Vue.http.options.root = 'http://api.domain.com/v1/'
becomes
Vue.http.options.root = 'http://api.domain.com/v1'
And with that, it will work!
Vue Resource root options not used?的更多相关文章
- vue resource 携带cookie请求 vue cookie 跨域
vue resource 携带cookie请求 vue cookie 跨域 1.依赖VueResource 确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm instal ...
- vue之$root,$parent
$root vue状态管理使用vuex,如果项目不大,逻辑不多,name我们没必要用vuex给项目增加难度,只需要用$root设置vue实例的data就行了,如下 main.js new Vue({ ...
- vue 中 this.$options.data() 重置
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue -resource 文件提交提示process,或者拦截处理
this.$http.post('url',fd||data,{emulateJSON:true}).then(fn(res){},fn(res){}) process成功案例 _self.$http ...
- vue resource 携带cookie请求 vue cookie 跨域(六)
1.依赖VueResource 确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm install vue-resource --save 在主方法添加 过滤 Vue.h ...
- vue resource patch方法的传递数据 form data 为 [object Object]
今天在测试 iblog 登录时,传送过去的数据总是 [object Object],以至于后台识别不出来. vue 使用了 vueResource 组件,登录方法为 patch. 经过探索,终于在官网 ...
- [VUE ERROR] Invalid options in vue.config.js: "publicPath" is not allowed
项目在build的时候报的这个错误: 具体原因是因为版本支持的问题,publicPath 属性到 vue-cli 3.2.0 之后才支持,所以将 publicPaht 改成 baseUrl 即可,或者 ...
- vue前后台数据交互vue-resource文档
地址:https://segmentfault.com/a/1190000007087934 Vue可以构建一个完全不依赖后端服务的应用,同时也可以与服务端进行数据交互来同步界面的动态更新. Vue通 ...
- 用vue构建多页面应用
最近一直在研究使用vue做出来一些东西,但都是SPA的单页面应用,但实际工作中,单页面并不一定符合业务需求,所以这篇我就来说说怎么开发多页面的Vue应用,以及在这个过程会遇到的问题. 准备工作 在本地 ...
随机推荐
- python 多线程和多进程
多线程与多进程 知识预览 一 进程与线程的概念 二 threading模块 三 multiprocessing模块 四 协程 五 IO模型 回到顶部 一 进程与线程的概念 1.1 进程 考虑一个场景: ...
- VMware5.5-vCenter的安装准备及安装
vSphere 最近公司来了新同事,为了帮助他尽快熟悉VM-vsphere,一块复习了下,并把实验总结为文档. 声明:本例是以王隆杰老师的vsphere5.5教程为基础和线索进行的,由于时间匆忙,可能 ...
- [Win] Win8权限机制导致R安装包失败
在Rstudio安装tidyselect的时候,提示 ERROR: compilation failed for package ‘tidyselect’ 搜了一下,在github上找到tidysel ...
- Centos7常用操作
1.装完系统无法用scrt连接服务器 查看IP命令 ip addr [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33 ...
- 51nod 算法马拉松30
题目链接 附一个代码地址 A,这个容斥一下就好了 C,rxd大爷给讲的,首先如果分三种情况(成环,正在比配环,未访问)讨论复杂度是\(3^n * n ^ 2\)的,但是对于每一个环,都可以直接枚举环的 ...
- [CSAcademy]Or Problem
[CSAcademy]Or Problem 题目大意: 一个长度为\(n(n\le2\times10^5)\)的序列\(A(0\le A_i<2^{20})\),将其分为恰好\(m\)个连续段, ...
- MPU和CPU有什么区别?
MPU(或称MP,微处理器)和CPU(中央处理器)同为处理器,但范畴不同. 计算机(即电脑)分为巨型机,大型机,中型机,小型机和微型计算机5类.这5类计算机的运算核心统称为CPU,而MPU只是微型计算 ...
- LINUX文件内容处理及文本编辑器vim
Linux基本操作命令 echo命令 echo命令: 把echo后面的内容显示到屏幕. -n 显示内容的时候不显示每行结尾的回车 echo 内容 >> 文件名 表示把内容加到一个文件的末尾 ...
- ES6字符串和正则表达式改动
1. ES6字符串变更 (1)includes() 方法,如果在字符串中检测到指定文本返回true,否则返回false (2)startsWith()方法,如果在字符串的起始部分检测到文本,则返回tr ...
- 弱智的grub消除法
GRUB GNU GRUB(简称"GRUB")是一个来自GNU项目的启动引导程序.GRUB是多启动规范的实现,它允许用户可以在计算机内同时拥有多个操作系统,并在计算机启动时选择希望 ...