vue-cli3(cli3 文件中没有vue.config.js ,进行额外的配置)
本地项目调后台接口,会跨域,为了解决这个问题 进行代理配置
需要新建vue.config.js
vue.config.js 中
const {
defineConfig
} = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
lintOnSave: false,
devServer: {
proxy: {
'/': {
// 此处的写法,目的是为了 将 /api 替换成 https://www.baidu.com/
target: 'http://localhost:8081',
// 允许跨域
changeOrigin: true,
ws: false,
pathRewrite: {
'^/': ''
}
}
}
}
})
调用 /api 就会自动匹配到 http://172.16.8.51:8083
const url = '/api/login';
post(url)
欢迎转载,转载请标注出处。关注公众号: JAVA大师, 后台回复 资源,既可获取资源链接 !!!