猿问

vue在开发模式下,怎么改变向后台发送请求的默认地址

向后台发送请求现在的写法
this.$http.get('http://1.1.1.1:8080/product/getAllProducts?page=0')
.then((response)=>{
me.tableData=response.body.data.content
})
.catch(function(response){
/**
*todo:此处待补充错误处理
**/
})
我希望改成下面写法但是效果还是http://1.1.1.1:8080/product/getAllProducts?page=0
this.$http.get('product/getAllProducts?page=0')
.then((response)=>{
me.tableData=response.body.data.content
})
.catch(function(response){
/**
*todo:此处待补充错误处理
**/
})
为此,我改了config/index.js文件中的
dev:{
proxyTable:{
'/api':{
target:'http://1.1.1.1:8080',
changeOrigin:true
}
}
但是并不能实现我想要的效果,求助求助
注意:我用的是vue-resource,怎么写呢?而且我就是开发模式下请求需要指定地址,在build模式下正常使用localhost
弑天下
浏览 2860回答 2
2回答

沧海一幻觉

this.$http.get('product/getAllProducts?page=0')请求前面少了一个'/',改成this.$http.get('/product/getAllProducts?page=0'),其实可以控制台调试一下,看看接口请求的详细信息,一步一步找原因可以找到的。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答