1,在要被引入的文件中
module.exports = {
interfaceIP: "http://172.16.170.135:900/PEapi"
}
2,在vue.config.js中,
const interfaceIP = require('./public/configip');
console.log(interfaceIP)
console.log(interfaceIP.interfaceIP)
module.exports = {
productionSourceMap: false,
// 是否是生产环境
publicPath: './',
devServer: {
hot: true,
// port: 8071,
proxy: {
'/api': {
target: interfaceIP.interfaceIP,
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
},
}
target就可以写成动态的了,
3,import对应的是export或export default
require对应的是exports或module.exports