微信小程序在解包後,會出現vd_version_info is not defined 的錯誤提示,這是解包程序和微信小程序版本升級之間的差異造成的,微信小程序的版本升級會對封包解包產生影響,那麼問題如何解決呢?
其實解包程序也是基於js開發的,所以解決辦法自然就是對準js代碼進行修復。
對應的就是如下代碼文件
修改wxappUnpacker文件中的 wuWxss.js
function runVM(name, code) {
//這是原來的代碼
//let wxAppCode={},handle={cssFile:name};
//let vm=new VM({sandbox:Object.assign(new GwxCfg(),{__wxAppCode__:wxAppCode,setCssToHead:cssRebuild.bind(handle)})});
//vm.run(code);
//for(let name in wxAppCode)if(name.endsWith(".wxss")){
//handle.cssFile=path.resolve(frameName,"..",name);
//wxAppCode[name]();
//}
//一下爲新修改的代碼:
let wxAppCode = {};
let handle = {cssFile: name};
let gg = new GwxCfg();
let tsandbox = {
$gwx: GwxCfg.prototype["$gwx"],
__mainPageFrameReady__: GwxCfg.prototype["$gwx"], //解決 $gwx is not defined
__vd_version_info__: GwxCfg.prototype["$gwx"], //解決 __vd_version_info__ is not defined
__wxAppCode__: wxAppCode,
setCssToHead: cssRebuild.bind(handle)
}
let vm = new VM({sandbox: tsandbox});
vm.run(code);
for (let name in wxAppCode) {
if (name.endsWith(".wxss")) {
handle.cssFile = path.resolve(frameName, "..", name);
wxAppCode[name]();
}
}
}
經過修復後再次運行解包程序,對微信小程序進行解包,圓滿解決,微信小程序正常的還原了出來。
小程序升級後,加了一些功能特性,所以對應的解藥也要增加一些變動支持。