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使用Mybatis-Generator
本文介绍如何将Maven和Mybatis-Generator配合使用. 简介 Mybatis-Generator是Mybatis提供的一个便捷型插件,自动可以为项目生产对应的实体类,Mapper,da ...
- 2019-1-23IntelliJ IDEAget的使用教程及出现的问题
第一条:快捷键: Ctrl+Alt+h:显示调用当前方法的所有位置. Ctrl+Alt+B:跳转到方法实现处 自动修正,我这是 Alt + L Ctrl+Enter,导入包,自动修正Ctrl+Alt+ ...
- vs各种版本
文件名称 文件大小 百度网盘下载 微软官方下载 Visual Studio 2015 Enterprise - 企业版 - 简体中文 3.89GB http://pan.baidu.com/s/1bn ...
- Java笔记(十九) 反射
反射 反射是在运行时获取类型的信息,再根据这些信息进行操作. 一.Class类 每个已加载的类在内存中都有一份类信息,每个对象都有指向它的类信息的引用. 在Java中,类信息对应的类就是java.la ...
- [LOJ6469]Magic
[LOJ6469]Magic 题目大意: 有\(n(n\le10^5)\)个物品,每个物品有一个权值\(w_i(w_i\le10^{18})\).求所有\(n\choose 2\)对物品\((i,j) ...
- C#7.0&6.0新特性 — 完整版
C#2.0 泛型 部分类型 匿名方法 迭代器 可空类型 Getter / setter单独可访问性 方法组转换(代表) Co- and Contra-variance for delegates 静态 ...
- 变量安全过滤,防止xss攻击
下面这个方法不管是字符串还是数组,都可以进行过滤 /** * @purpose : 对变量进行安全过滤,使 $_GET.$_POST.$q->record 等变量更安全 * @author : ...
- javaweb数据库编程代码详细讲解
import java.sql.*; /*默写数据库练习数据库编程及注释讲解代码*/ public class Main{ public static void main(String[]args)t ...
- Jsp俩大内置对象学习
https://www.cnblogs.com/smyhvae/p/4065790.html post与get的区别 最直观的区别就是GET把参数包含在URL中,POST通过request body传 ...
- Spring MVC4 + Spring Security4 + Hibernate实例
http://www.yiibai.com/spring-security/spring-mvc-4-and-spring-security-4-integration-example.html 在这 ...