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应用,以及在这个过程会遇到的问题. 准备工作 在本地 ...
随机推荐
- SpringBoot邮件发送
这篇文章介绍springboot的邮件发送. 由于很简单就没有分出server和imp之类,只是在controller简单写个方法进行测试. 首先pom文件加入spring-boot-starter- ...
- iOS12系统应用开发发送邮件
iOS12系统应用开发发送邮件 消息分享是应用社交化和营销的重要途径.除了开发者自己搭建专有的消息分享渠道之外,还可以借助系统自带的各种途径.iOS提供了3种快速分享消息的方式,分别为发送邮件.发送短 ...
- 2602 ACM 杭电 骨头容器 01背包
题意:装骨头的容器大小固定,有一堆骨头,已知骨头的价值和大小,在不超过容积大小的情况下,问:所装骨头的最大价值? 思路:典型的01背包问题,不需要有任何的变动. 模板: for(int j=v;j&g ...
- SpringMVC的请求处理流程
- 用canvas写个接水管小游戏
声明:本文为原创文章,如需转载,请注明来源WAxes,谢谢! 过年的十八天假期迷迷糊糊一下子就过去了(LZ还是实习生,鉴于大学最后一个寒假了,所以就多请了好多天假),又要返工上班了.这是年后的第一篇博 ...
- C++学习笔记56:异常处理
异常处理 异常处理的语法 抛掷异常的程序段 throw表达式: 捕获并处理异常的程序段 try 复合语句 catch(异常声明) 复合语句 catch(异常声明) 复合语句 注意:如果匹配的处理器没有 ...
- 点击时出现某个样式,1s后移除该样式的案例效果
这里为了使效果更好的让用户体现出来,点击时添加的样式为background:yellow;1后移除该样式: 案例demo为: <!DOCTYPE html> <html lang=& ...
- Oracle分组小计、总计示例(grouping sets的使用)
1.首先创建一个表 create table TE ( ID VARCHAR2(2), T_CODE VARCHAR2(4), T_NAME VARCHAR2(4), T_A ...
- CSS_高级选择符
2016-11-07 <css入门经典>第八章 1.属性选择器 选择器 描述 [attribute] 用于选取带有指定属性的元素. [attribute=value] 用于选取带有指定属性 ...
- aix 查看内存,CPU 配置信息
内存lsattr -El mem0cpu lsdev -C |grep procCPU的信息lsattr -El proc0 #bootinfo -r查看物理内存 使用命令# lsdev ...