vue开发移动端app,做版本更新,下载安装包后自动安装。用html5+但是不成功,有没有大神知道解决办法。
以下是我的代码
main.js
var onPlusReady = function (callback, context = this) {
if (window.plus) {
callback.call(context)
} else {
document.addEventListener('plusready', callback.bind(context))
}
}
Vue.mixin({
beforeCreate () {
onPlusReady(() => {
this.plusReady = true
}, this)
},
methods: {
onPlusReady: onPlusReady
}
})
****.vue
// 下载apk文件
downloadApk(url) {
console.log(url);
let that = this;
plus.runtime.openURL(url);
const dtask = plus.downloader.createDownload(
url,
{ filename: "_doc/update/" },
function(d, status) {
if (status === 200) {
// 安装apk资源包
that.installFlag = true;
that.path = d.filename;
}
}
);
dtask.start();
},
// 安装apk
installApk() {
this.onPlusReady(() => {
this.installFlag = false;
window.plus.nativeUI.showWaiting("安装更新");
window.plus.runtime.install(
this.path,
{},
function() {
window.plus.nativeUI.closeWaiting();
window.plus.nativeUI.alert("更新完成!", function() {
// 更新完成后重启应用
window.plus.runtime.restart();
});
},
function(e) {
window.plus.nativeUI.closeWaiting();
window.plus.nativeUI.toast("安装更新失败!");
}
);
});
},
打包成app在手机上测试不成功