接口
http://11x.21x.8x.3:8091/intmotx/1.json
vue.config.js
const { defineConfig } = require('@vue/cli-service')
// module.exports = defineConfig({
// transpileDependencies: true,
// lintOnSave:false
// })
module.exports = defineConfig({
devServer: {
proxy: {
'/api': {
target: 'http://11x.21x.8x.3:8091', //這裏填入你要請求的接口的前綴
ws: true, //代理websocked
changeOrigin: true, //虛擬的站點需要更換origin
secure: true, //是否https接口,我用的http但是我變成false他打包後會報錯,所以先true
pathRewrite: {
'^/api': '' //重寫路徑
}
}
}
},
lintOnSave:false
})
service.js
const Service = axios.create({
timeout:8000,
baseURL:"/api",
headers:{
"Content-type":"application/json;charset=utf-8",
// "Authorization":store.state.uInfo.userInfo.token
}
})
request.js
// 獲取用戶列表
export const userListApi=data=>{
return get({
url:"/intmote/1.json",
data
})
}
代理成功