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整合elasticsearch
在这一篇文章开始之前,你需要先安装一个ElasticSearch,如果你是mac或者linux可以参考https://www.jianshu.com/p/e47b451375ea,如果是windows ...
- jquery 1.7.2源码解析(二)构造jquery对象
构造jquery对象 jQuery对象是一个类数组对象. 一)构造函数jQuery() 构造函数的7种用法: 1.jQuery(selector [, context ]) 传入字符串参数:检查该字符 ...
- LeetCode Weekly Contest 32
581. Shortest Unsorted Continuous Subarray Given an integer array, you need to find one continuous s ...
- URL结构
一.概念 URL:统一资源定位符 (Uniform Resource Locator, URL). 完整的URL由这几个部分构成:scheme://host:port/path?query#hash: ...
- git https 请求报错 504
git https 请求报错 504 原因可能是因为设置了代理,ubuntu/deepin 系统可以检查 /etc/profile ~/.bashrc 内有没有设置 https 的代理. 有的话,去掉 ...
- python 3.5 连接mysql数据库
python 3.5 要连接mysql数据库,必须先安装pymysql模块,该模块可以操作mysql数据. 1.安装pymysql模块:使用pip进行安装 cmd打开运行模式,切换目录到pip的scr ...
- 移动端适配问题px->rem方法
移动端web页面适配问题 1.引入插件 github地址:https://github.com/re54k/mobileweb-utilities/blob/master/util/mobile-ut ...
- IO流(5)—缓冲流
1.IO体系: 抽象基类--节点流(文件流)--缓冲流(处理流的一种) InputStream --FileInputStream--BufferedInputStream OutputStream- ...
- .NET语言的编译过程:中间语言(IL)和即时编译器(JIT)
.NET语言的编译分为两个阶段.首先高级语言被编译成一种称作IL的中间语言,与高级语言相比,IL更像是机器语言,然而,IL却包含一些抽象概念(比如:类.异常),这也是这种语言被称为中间语言的原因.IL ...
- ASP.NET WebApi服务接口如何防止重复请求实现HTTP幂等性
一.背景描述与课程介绍 明人不说暗话,跟着阿笨一起玩WebApi.在我们平时开发项目中可能会出现下面这些情况; 1).由于用户误操作,多次点击网页表单提交按钮.由于网速等原因造成页面卡顿,用户重复刷新 ...