本地运行 获取不到 window.pluginWebUpdateNotice_,部署到线上可以获取到
配置版本:
vite.config.js:
在全局请求拦截里面监听 axios.js: `//HTTPrequest拦截 axios.interceptors.request.use( config => { // start progress bar NProgress.start(); //地址为已经配置状态则不添加前缀 if (!isURL(config.url) && !config.url.startsWith(baseUrl)) { config.url = baseUrl + config.url; } //headers判断是否需要 const authorization = config.authorization === false; const token = getToken(); if (!authorization) { config.headers['Authorization'] = token; } //headers判断请求是否携带token const meta = config.meta || {}; const isToken = meta.isToken === false; //headers传递token是否加密 const cryptoToken = config.cryptoToken === true; //判断传递数据是否加密 const cryptoData = config.cryptoData === true;
if (token && !isToken) {
config.headers[website.tokenHeader] = cryptoToken
? 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey)
: 'bearer ' + token;
}
// 开启报文加密
if (cryptoData) {
if (config.params) {
const data = crypto.encryptAES(JSON.stringify(config.params), crypto.aesKey);
config.params = { data };
}
if (config.data) {
config.text = true;
config.data = crypto.encryptAES(JSON.stringify(config.data), crypto.aesKey);
}
}
//headers中配置text请求
if (config.text === true) {
config.headers['Content-Type'] = 'text/plain';
}
//headers中配置serialize为true开启序列化
if (config.method === 'post' && meta.isSerialize === true) {
config.data = serialize(config.data);
}
console.log('_____________******')
console.log(window.pluginWebUpdateNotice_)
//window.pluginWebUpdateNotice_.checkUpdate()
return config;
}, error => { return Promise.reject(error); } );`
本地是不注入脚本的,因为本地没法模拟更新的条件
本地是不注入脚本的,因为本地没法模拟更新的条件
有什么合适的方案解决这个问题吗 现在两个问题,1.本地运行时候因为拿不到变量会报错 2.本地无法验证,每次都要部署测试环境才能验证,流程比较消耗时间
if(!import.meta.env.Dev) { // 或者 process.env.NODE_ENV !== 'development'
window.pluginWebUpdateNotice_.checkUpdate()
}
if(!import.meta.env.Dev) { // 或者 process.env.NODE_ENV !== 'development' window.pluginWebUpdateNotice_.checkUpdate() }
谢谢 我用下这种
请问rect使用的是nextJS 框架,没有固定的index.html,要如何使用呢?因为没有固定的html,所以会在运行时报错说找不到对应的html