vue-resource请求。

在main.js中配置了请求接口的根目录,但是在请求时会报错

main.js中配置:

Vue.http.options.root = 'http://www.liulongbin.top:3005';

vue-resource请求:


getlist(){
        this.$http.get('/api/getnewslist').then(function (res) {
                console.log(res.body)
            })
        }

在浏览器中显示这样的错误:
image.png
为什么请求变成了http://localhost/xxx

阅读 2.1k
1 个回答

vue-resourse文档上说:

Note that for the root option to work, the path of the request must be relative. This will use this the root option: Vue.http.get('someUrl') while this will not: Vue.http.get('/someUrl
请注意,要使根选项起作用,请求的路径必须是相对的。这将使用根选项:Vue.http.get('someUrl'),而不是:Vue.http.get('/someUrl')。

另外,vue-resourse已经是过去式了,建议替换成axios。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题