本文环境:windows7、vue2.9.6,该方法适用于所有品牌的电脑。

配置vue.js环境的方法:

第一步创建一个文件夹,在创建者三个js文件。

6b0fef959af43634b1f46577ae54744.png

b3b7c459de356e7917a2605740eb83a.png

69878ec5743304118cfb311fdcdab36.png

第二步进入config.js文件

// 默认是本地环境
if(env==='production'){ // 生产环境
target = proEnv.hosturl;
}else if(env==='test'){ // 测试环境
target = testEnv.hosturl;
}else if(env == 'development'){ // 本地环境
target = devEnv.hosturl;
}
// 生成代理配置对象
let proxyObj = {};
devProxy.forEach((value, index) => {
proxyObj[value] = {
target: target,
changeOrigin: true,
pathRewrite: {
[`^${value}`]: value
}
};
});
module.exports = {
baseUrl: '/',
outputDir: 'dist',
devServer: {
open:true,
// host: 'localhost',
host: '0.0.0.0',
port: 1999,
https: false,
hotOnly: false,
proxy: {
'/api':{
target:'https://xxx.xxx.xxx.xxx',
pathRewrite:{
'/api':'/api/api'
}
},
}
}
};

以上就是如何配置vue.js环境的详细内容,更多请关注其它相关文章!