原理:利用本地服务器的代理功能,类似于nginx的反向代理解决跨域问题
大概配置如下
assetsSubDirectory: '',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: '***********************', //源地址
changeOrigin: true, //改变源
pathRewrite: {
'^/api': '' //路径重写
}
}
在请求接口的时候这样写
getNewsInfoList () {
this.$http({
method: 'get',
url: '/api/home',
params: {
page: this.page,
pageSize: this.pageSize
}
}).then((res) => {
var data = res.data
if (this.flag == 0) {
// this.newsList = data.list.concat(this.newsList)
}else{
this.newsList = this.newsList.concat(data.list)
done()
}
}).catch((error) => {
})
}
博客介绍利用本地服务器的代理功能解决跨域问题,原理类似nginx的反向代理,并提及大概配置,还指出请求接口时的写法。
8119

被折叠的 条评论
为什么被折叠?



