Vue HTML5+ APP热更新
<script>
export default {
data() {
return {
version: "2.0.5",
};
},
methods: {
// 下载wgt文件
downWgt(wgtUrl) {
const that = this;
plus.nativeUI.showWaiting("发现新版本,正在下载更新文件,请稍后...");
plus.downloader
.createDownload(
wgtUrl,
{
filename: "_doc/update/",
},
function (d, status) {
if (status == 200) {
console.log("下载更新文件成功:" + d.filename);
that.installWgt(d.filename); //安装wgt包
} else {
console.log("下载失败!");
plus.nativeUI.alert("下载失败!");
plus.nativeUI.alert(JSON.stringify(d));
plus.nativeUI.alert(status);
}
plus.nativeUI.closeWaiting();
}
)
.start();
},
installWgt(path) {
plus.nativeUI.showWaiting("正在安装更新文件...");
plus.runtime.install(
path,
{},
function () {
plus.nativeUI.closeWaiting();
console.log("安装更新文件成功!");
plus.nativeUI.alert("应用资源更新完成!", function () {
plus.runtime.restart();
});
},
function (e) {
plus.nativeUI.closeWaiting();
console.log("安装更新文件失败[" + e.code + "]:" + e.message);
plus.nativeUI.alert("安装更新文件失败[" + e.code + "]:" + e.message);
if (e.code == 10) {
alert("请清除临时目录");
}
}
);
},
plusReady() {
const that = this;
// plus.nativeUI.alert(plus.runtime.version);
this.post("login/app_update", {
version: this.version,
}).then((res) => {
const resData = res.data;
if (resData.data.update === 1) {
this.downWgt(resData.data.upgradeUrl);
}
});
},
},
mounted() {
this.post("login/app_update", {
version: this.version,
}).then((res) => {});
if (window.plus) {
this.plusReady();
} else {
document.addEventListener("plusready", this.plusReady, false);
}
},
};
</script>
更多内容参考uni-app 整包升级/更新方案
分类:
前端
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧