日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

Vue封装hbuilder热更新

發布時間:2024/9/27 vue 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vue封装hbuilder热更新 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
main.js
import AutoUpdateApp from './common/AutoUpdateApp/AutoUpdateApp' //我存放AutoUpdateApp.js的目錄 Vue.use(AutoUpdateApp)
AutoUpdateApp.js
export default {install(Vue,options){Vue.prototype.AutoUpdateApp = function () {return {// 獲取本地應用資源版本號getVersion: function (CallBack) {var wgtVer = null;//異步操作plus.runtime.getProperty(plus.runtime.appid,(info) => {wgtVer = info.version;CallBack(wgtVer);});},//下載wgt文件downWgt: function (wgtUrl) {var self = this;plus.nativeUI.showWaiting("下載更新文件...");plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){if ( status == 200 ) { console.log("下載更新文件成功:" + d.filename);self.installWgt(d.filename); // 安裝wgt包} else {plus.nativeUI.alert("下載失敗!");}plus.nativeUI.closeWaiting();}).start();},// 更新應用資源installWgt: function (path) {plus.nativeUI.showWaiting("安裝更新文件...");plus.runtime.install(path,{},function(){plus.nativeUI.closeWaiting();plus.nativeUI.alert("應用資源更新完成!",function(){plus.runtime.restart();});},function(e){plus.nativeUI.closeWaiting();plus.nativeUI.alert("安裝更新文件失敗[" + e.code + "]:" + e.message);if(e.code == 10){plus.nativeUI.alert('請清除臨時目錄');}});}}};}}
vuex的store.js文件的actions
autoupdateapp: function (context) {let AutoUpdateApp = new window.Vue.AutoUpdateApp();let wgtVer = plus.runtime.version;axios.post('/point-api-autoupdateapp',{appid:plus.runtime.appid,appname:'queue'}).then(function(response){ let newVer = response;//檢查更新if(wgtVer && newVer && (wgtVer.substring(0,3) < newVer.versionName.substring(0,3))){if(window.confirm('檢測到更新,是否更新?')){AutoUpdateApp.downWgt(newVer.apk); }} }, function(response){mui.toast('網絡錯誤');});}
在需要的組件的 mounted或created調用
// 初始化創建對象mui.plusReady(() => {this.$store.dispatch('autoupdateapp');});

php的models代碼

public static function AutoUpdateApp($params) {extract($params);$versionName = '';if($appname == 'queue'){$versionName = '1.2.0';}elseif($appname == 'waiter'){$versionName = '1.2.0';}elseif($appname == 'pos'){$versionName = '1.2.0';}$data = ['versionName' => $versionName,'apk' => $SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/app/'.$appid.'.wgt',//存放更新資源的目錄];return self::formatBody('data' => $data); }

總結

以上是生活随笔為你收集整理的Vue封装hbuilder热更新的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。