1、unipp中,页面生命周期onShow获取上一个传过来的options值。
答:onShow() {
// 获取当前小程序的页面栈
let pages = getCurrentPages();
// 数组中索引最大的页面--当前页面
let currentPage = pages[pages.length-1];
// 打印出当前页面中的 options
console.log(currentPage.options) //正常打印出 options 值
}
2、uniapp获取版本号和应用版本号、设备型号。
答:
//#ifdef APP-PLUS
console.log('版本',plus.runtime.versionCode)
// this.version=plus.runtime.versionCode
// 获取本地应用资源版本号
plus.runtime.getProperty(plus.runtime.appid, (info) => {
console.log(JSON.stringify(info));
this.version = info.version;
// this.versionCode = info.versionCode ;
})
//设备型号
uni.getSystemInfoSync().platform
//#endif
3、uniapp的H5页面获取手机上的返回键。
const that = this
var webview = plus.webview.currentWebview();//获取窗口
plus.key.addEventListener('backbutton', function() {
//监听返回事件
webview.canBack(function(e) {
if (e.canBack) {
uni.webView.switchTab({
url: '/pages/index/datav'
})
} else {
console.log(22222);
}
})
});