项目作者: vue-html5plus

项目描述 :
一个基于html5plus标准的vuejs原生拓展插件!
高级语言: JavaScript
项目地址: git://github.com/vue-html5plus/vue-html5plus.git
创建时间: 2016-07-03T11:00:10Z
项目社区:https://github.com/vue-html5plus/vue-html5plus

开源协议:

下载


vue-html5plus

一个基于html5plus标准的vuejs原生拓展插件!

Downloads
Version
License

安装

引用 CDN 或 直接下载并用 <script> 标签引入:

  1. <script src="https://unpkg.com/vue-html5plus@1.0.0"></script>

大型项目可以使用 npm 安装:

  1. npm install vue-html5plus --save

调用:

  1. Vue.use(VueHtml5Plus);

入门

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport"
  6. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
  7. <title></title>
  8. <link href="css/mui.min.css" rel="stylesheet"/>
  9. </head>
  10. <body>
  11. <div id="app">
  12. <header class="mui-bar mui-bar-nav">
  13. <h1 class="mui-title">{{title}}</h1>
  14. </header>
  15. <div class="mui-content mui-content-padded">
  16. <p>定位城市:{{city}}</p>
  17. <p>网络信息:{{networkType}}</p>
  18. </div>
  19. </div>
  20. <script src="js/vue.js"></script>
  21. <script src="js/vue-html5plus.js"></script>
  22. <script type="text/javascript" charset="utf-8">
  23. new Vue({
  24. el: '#app',
  25. data: {
  26. title: 'hello vue-html5plus!',
  27. city: '',
  28. networkType: ''
  29. },
  30. mounted: function () {
  31. console.log(JSON.stringify(Vue.os))
  32. },
  33. plusReady: function () {
  34. // 获取定位信息
  35. this.$geolocation.getCurrentPosition().then(function (position) {
  36. this.city = position.address.city;
  37. });
  38. // 获取网络信息
  39. this.networkType = this.$networkinfo.getCurrentNetworkType();
  40. }
  41. })
  42. </script>
  43. </body>
  44. </html>

API

选项 —— plusReady 和 实例方法 —— plusReady

vue-htmlplus插件中Vue生命周期中添加了plusReady钩子,但是这个钩子不能用于组件及路由中。

  1. new Vue({
  2. el: '#app',
  3. plusReady: function () {
  4. // ...
  5. }
  6. })

可以在Vue其他生命周期使用$plusReady方法,如mounted中使用5+ API:

  1. this.plusReady(function() {
  2. // ...
  3. })

实例属性 —— os

一个用于判断当前运行环境的对象。

  1. {
  2. "plus":true,
  3. "stream":false,
  4. "wechat":false,
  5. "android":true,
  6. "iphone":false,
  7. "ipad":false,
  8. "version":"6.0",
  9. "isBadAndroid":false
  10. }

实例方法 —— $nativeUI

  • toast (message, duration, align) :显示自动消失的提示消息
  • alert (message, alertCB, title, buttonCapture) :弹出系统提示对话框
  • confirm (message, confirmCB, title, buttons) :弹出系统确认对话框
  • prompt (message, promptCB, title, tip, buttons) :弹出系统输入对话框
  • actionSheet (actionsheetStyle, actionsheetCallback) :弹出系统选择按钮框

实例方法 —— $accelerometer(加速度传感器)

获取当前设备的加速度信息:

  1. this.$accelerometer.getCurrentPosition().then(function (acceleration) {
  2. // ...
  3. });

监听设备加速度变化信息:

  1. this.$accelerometer.watchAcceleration().then(function (acceleration) {
  2. // ...
  3. });

实例方法 —— $geolocation(设备位置信息)

获取当前设备位置信息:

  1. this.$geolocation.getCurrentPosition(option).then(function (position) {
  2. // ...
  3. });

监听设备位置变化信息:

  1. this.$geolocation.watchPosition(option).then(function (position) {
  2. // ...
  3. });

关闭监听设备位置信息:

  1. this.$geolocation.clearWatch(watchId);

实例方法 —— $networkinfo

获取网络信息:

  1. this.$networkinfo.getCurrentNetworkType();