vue-cli3.0 axios跨域请求代理配置及端口修改
1.安装 axiosvue add axios2.项目根目录下新建 vue.config.js// vue.config.jsmodule.exports = {devServer: {port: 端口号,proxy: {'/apis': {target: 'https://mov...
·
1.安装 axios
vue add axios
2.项目根目录下新建 vue.config.js
// vue.config.js
module.exports = {
devServer: {
port: 端口号,
proxy: {
'/apis': {
target: 'https://movie.douban.com/', // target host
ws: true, // proxy websockets
changeOrigin: true, // needed for virtual hosted sites
pathRewrite: {
'^/apis': '' // rewrite path
}
},
}
}
};
3. 重启服务npm run serve
4. *.vue 文件中请求实例
this.axios.get('/apis/ithil_j/activity/movie_annual2017').then(res => {
console.log(res.data)
}, res => {
console.info('调用失败');
})
更多推荐
已为社区贡献8条内容
所有评论(0)