vue-element-admin 项目中的url打包到外部可修改

1.引入webpack 插件

npm install generate-asset-webpack-plugin --save-dev

2.在vue.config.js 中引入插件


const GenerateAssetPlugin = require('generate-asset-webpack-plugin')

3.createServerConfig 中 存放要打包隔离的文件

var createServerConfig = function(compilation){
let cfgJson={ApiUrl:"http://www.adoctors.cn"};
return JSON.stringify(cfgJson);
}

4.vue.config.js中configurewebpack对象下引入generate-asset-webpack-plugin插件,此时build:prod 已经能看到serverconfig.json 文件

plugins:[new GenerateAssetPlugin({
filename: 'serverconfig.json',
fn: (compilation, cb) => {
cb(null, createServerConfig(compilation));
},
extraFiles: []
})]

5.在项目入口处获取json文件的内容,并存入全局,(sessionStorage),接口的beseurl 获取相应需要的地址即可

Vue.prototype.getConfigJson=function(){
this.$http.get("serverconfig.json").then((result)=>{
//用一个全局字段保存ApiUrl 也可以用sessionStorage存储
Vue.prototype.ApiUrl=result.body.ApiUrl;
}).catch((error)=>{console.log(error)});
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值