A Native Extension Plugin for Vuejs Based on The Html5plus Standard

vue-html5plus

A native extension plugin for vuejs based on the html5plus standard!

installation

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);

getting Started

<!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>

API

Option-plusReady and instance method-plusReady

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() {
    // ...
})

Instance attributes-os

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
}

Instance method-$nativeUI

  • toast (message, duration, align): display the prompt message that disappears automatically
  • alert (message, alertCB, title, buttonCapture): system prompt dialog box pops up
  • confirm (message, confirmCB, title, buttons) :The system confirmation dialog box pops up
  • prompt (message, promptCB, title, tip, buttons): pop up the system input dialog box
  • actionSheet (actionsheetStyle, actionsheetCallback): pop up the system selection button box

Example method-$accelerometer (accelerometer)

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) {
    // ...
});

Example method-$geolocation (device location information)

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);

Example method-$networkinfo

Get network information:

this.$networkinfo.getCurrentNetworkType();

Download Details:

Author: vue-html5plus

Source Code: https://github.com/vue-html5plus/vue-html5plus

#vue #vuejs #javascript

A Native Extension Plugin for Vuejs Based on The Html5plus Standard
4.55 GEEK