A native extension plugin for vuejs based on the html5plus standard!
CDN or direct references to download and use <script>
the introduction of the label:
<script src="https://unpkg.com/vue-html5plus@1.0.0"></script>
Large projects can be installed using npm:
npm install vue-html5plus --save
transfer:
Vue.use(VueHtml5Plus);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
<title></title>
<link href="css/mui.min.css" rel="stylesheet"/>
</head>
<body>
<div id="app">
<header class="mui-bar mui-bar-nav">
<h1 class="mui-title">{{title}}</h1>
</header>
<div class="mui-content mui-content-padded">
<p>定位城市:{{city}}</p>
<p>网络信息:{{networkType}}</p>
</div>
</div>
<script src="js/vue.js"></script>
<script src="js/vue-html5plus.js"></script>
<script type="text/javascript" charset="utf-8">
new Vue({
el: '#app',
data: {
title: 'hello vue-html5plus!',
city: '',
networkType: ''
},
mounted: function () {
console.log(JSON.stringify(Vue.os))
},
plusReady: function () {
// 获取定位信息
this.$geolocation.getCurrentPosition().then(function (position) {
this.city = position.address.city;
});
// 获取网络信息
this.networkType = this.$networkinfo.getCurrentNetworkType();
}
})
</script>
</body>
</html>
The plusReady hook is added to the Vue life cycle in the vue-htmlplus plugin, but this hook cannot be used in components and routing.
new Vue({
el: '#app',
plusReady: function () {
// ...
}
})
You can use the $plusReady method in other life cycles of Vue, such as using 5+ API in mounted:
this.plusReady(function() {
// ...
})
An object used to determine the current operating environment.
{
"plus":true,
"stream":false,
"wechat":false,
"android":true,
"iphone":false,
"ipad":false,
"version":"6.0",
"isBadAndroid":false
}
Get the acceleration information of the current device:
this.$accelerometer.getCurrentPosition().then(function (acceleration) {
// ...
});
Monitor device acceleration change information:
this.$accelerometer.watchAcceleration().then(function (acceleration) {
// ...
});
Get current device location information:
this.$geolocation.getCurrentPosition(option).then(function (position) {
// ...
});
Monitoring equipment location change information:
this.$geolocation.watchPosition(option).then(function (position) {
// ...
});
Turn off monitoring device location information:
this.$geolocation.clearWatch(watchId);
Get network information:
this.$networkinfo.getCurrentNetworkType();
Author: vue-html5plus
Source Code: https://github.com/vue-html5plus/vue-html5plus
#vue #vuejs #javascript