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?的更多相关文章

  1. vue resource 携带cookie请求 vue cookie 跨域

    vue resource 携带cookie请求 vue cookie 跨域 1.依赖VueResource 确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm instal ...

  2. vue之$root,$parent

    $root vue状态管理使用vuex,如果项目不大,逻辑不多,name我们没必要用vuex给项目增加难度,只需要用$root设置vue实例的data就行了,如下 main.js new Vue({ ...

  3. vue 中 this.$options.data() 重置

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. vue -resource 文件提交提示process,或者拦截处理

    this.$http.post('url',fd||data,{emulateJSON:true}).then(fn(res){},fn(res){}) process成功案例 _self.$http ...

  5. vue resource 携带cookie请求 vue cookie 跨域(六)

    1.依赖VueResource  确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm install vue-resource --save 在主方法添加 过滤 Vue.h ...

  6. vue resource patch方法的传递数据 form data 为 [object Object]

    今天在测试 iblog 登录时,传送过去的数据总是 [object Object],以至于后台识别不出来. vue 使用了 vueResource 组件,登录方法为 patch. 经过探索,终于在官网 ...

  7. [VUE ERROR] Invalid options in vue.config.js: "publicPath" is not allowed

    项目在build的时候报的这个错误: 具体原因是因为版本支持的问题,publicPath 属性到 vue-cli 3.2.0 之后才支持,所以将 publicPaht 改成 baseUrl 即可,或者 ...

  8. vue前后台数据交互vue-resource文档

    地址:https://segmentfault.com/a/1190000007087934 Vue可以构建一个完全不依赖后端服务的应用,同时也可以与服务端进行数据交互来同步界面的动态更新. Vue通 ...

  9. 用vue构建多页面应用

    最近一直在研究使用vue做出来一些东西,但都是SPA的单页面应用,但实际工作中,单页面并不一定符合业务需求,所以这篇我就来说说怎么开发多页面的Vue应用,以及在这个过程会遇到的问题. 准备工作 在本地 ...

随机推荐

  1. python数据结构之希尔排序

    def shell_sort(alist): n=len(alist) gap= int(n / 2) #步长 while gap>0: for i in range(gap,n): j=i w ...

  2. phpmyadmin 修改执行时间

    D:\xampp\phpMyAdmin\libraries\config.default.php $cfg['ExecTimeLimit'] = 0;

  3. BZOJ.4340.[BJOI2015]隐身术(后缀数组 搜索)

    BZOJ \(Description\) 给定两个串\(S,T\)以及一个数\(k\),求\(T\)中有多少个子串,满足和\(S\)的编辑距离不超过\(k\). \(|S|+|T|\leq10^5,\ ...

  4. HNOI 2017

    题目链接 我还是按bzoj AC数量排序做的 4827 这个其实如果推一下(求每个值)式子会发现是个卷积,然后FFT就好了 4826 记不太清了,可以求出每个点左右第一个比他的的点的位置,将点对看成平 ...

  5. Lock锁与Condition监视器(生产者与消费者)。

    /*生产者与消费者第二次敲,本人表示很郁闷,以后要经常读这个 * Condition 将Object类中的监视器(wait notify notifyAll)分解成不同的对象.例如condition_ ...

  6. IntelliJ IDEA配置Springboot2.x 通过devtools实现代码热部署,提高调试效率

    1.pom.xml添加依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifa ...

  7. NOIP不开心记(不开心的东西肯定不能给别人看!)

    写在前面的.. noip之后一直很想写一下什么的.. 老师:这就是你逃晚自习来机房的原因?? Day 0 坐了好久的车来到GZ.. 年年都是GZ.. sb酒店垃圾的要死.. 路上都是杀马特.. 隔壁还 ...

  8. python正则表达式(一)

    ---恢复内容开始--- 正则表达式,又称正规表示式.正规表示法.正规表达式.规则表达式.常规表示法(英语:Regular Expression,在代码中常简写为regex.regexp或RE),是计 ...

  9. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习9

    #include <iostream>#include <string>using namespace std;struct CandyBar{ //string kind;  ...

  10. TypeScript语法学习--基本类型

    查看官方文档手册:链接:https://www.tslang.cn/docs/home.html (一)Boolean 最基本的数据类型就是简单的true/false值 The most basic ...