zoukankan      html  css  js  c++  java
  • vue + cordova

    1.添加cordova项目

    $  cordova create myApp1 org.apache.cordova.myApp myApp2

    其中:

    • myApp1:cordova目录名
    • org.apache.cordova.myApp: 包名
    • myApp2: 项目名(在config.xml的<name>中查看)

    2.在vue中添加cordova的配置

    myApp1/www/index.html----->vue/index.html

    1. <html>
    2. <head>
    3. <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
    4. <meta name="format-detection" content="telephone=no">
    5. <meta name="msapplication-tap-highlight" content="no">
    6. <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    7. <link rel="stylesheet" type="text/css" href="css/index.css">
    8. <title>Hello World</title>
    9. </head>
    10. <body>
    11. <div class="app">
    12. <h1>Apache Cordova</h1>
    13. <div id="deviceready" class="blink">
    14. <p class="event listening">Connecting to Device</p>
    15. <p class="event received">Device is Ready</p>
    16. </div>
    17. </div>
    18. <script type="text/javascript" src="cordova.js"></script>
    19. <script type="text/javascript" src="js/index.js"></script>
    20. </body>
    21. </html>
    • <meta>拷贝到vue/index.html中
    • <script>关于cordova.js的引用拷贝到vue/index.html中

    myApp1/www/js/index.js----->vue/vuex/main.js

    1. var app = {
    2. // Application Constructor
    3. initialize: function() {
    4. this.bindEvents();
    5. },
    6. // Bind Event Listeners
    7. //
    8. // Bind any events that are required on startup. Common events are:
    9. // 'load', 'deviceready', 'offline', and 'online'.
    10. bindEvents: function() {
    11. document.addEventListener('deviceready', this.onDeviceReady, false);
    12. },
    13. // deviceready Event Handler
    14. //
    15. // The scope of 'this' is the event. In order to call the 'receivedEvent'
    16. // function, we must explicitly call 'app.receivedEvent(...);'
    17. onDeviceReady: function() {
    18. app.receivedEvent('deviceready');
    19. },
    20. // Update DOM on a Received Event
    21. receivedEvent: function(id) {
    22. var parentElement = document.getElementById(id);
    23. var listeningElement = parentElement.querySelector('.listening');
    24. var receivedElement = parentElement.querySelector('.received');
    25. listeningElement.setAttribute('style', 'display:none;');
    26. receivedElement.setAttribute('style', 'display:block;');
    27. console.log('Received Event: ' + id);
    28. }
    29. };
    30. app.initialize();

    1)内容拷贝到vue/src/vuex/main.js中

    2)onDeviceReady时启动app

    1. onDeviceReady: function () {
    2. //app.receivedEvent('deviceready');
    3. appRouter.start(App, 'app')
    4. window.navigator.splashscreen.hide()
    5. }

    3.创建android项目

    cordova platform add android

     

    4.添加cordova插件

    cordova plugin add xxxx

    5. 构建 vue项目

    npm run build

    6.文件转移

    将dist文件夹下的文件,拷贝到cordova/platforms/androd/assets/www目录下

    7.构建cordova项目

    cordova目录下:

    cordova build android    //构建apk

    cordova run android       //构建apk,并安装到连接的设备上

  • 相关阅读:
    运算符重载
    LPCRITICAL_SECTION 函数
    让你弄明白高斯核是怎样进行滤波工作的
    sln文件
    内联函数
    C++对文本的操作
    数组形参
    内存区划分、内存分配、常量存储区、堆、栈、自由存储区、全局区[C++][内存管理]
    怎样对付win7黑屏
    C++ 模板
  • 原文地址:https://www.cnblogs.com/jun3101s/p/5914325.html
Copyright © 2011-2022 走看看