首先要安裝一個包 vue-html5plus
npm i vue-html5plus -S
然后配置這個文件
在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
}
})
這樣就可以集成html5 plus了
使用方法示例:(獲取地理位置)
mounted () {
this.onPlusReady(function () {
plus.geolocation.getCurrentPosition(
this.geoInf, function (e) {
alert('獲取位置信息失敗:' + e.message)
},
{
geocode: false
} )
})
},