liuyuqi 2 years ago
parent
commit
ab8eb0c931
3 changed files with 57 additions and 4 deletions
  1. 10 0
      .vscode/preview.yml
  2. 7 0
      myApp/www/index.html
  3. 40 4
      myApp/www/js/index.js

+ 10 - 0
.vscode/preview.yml

@@ -0,0 +1,10 @@
+
+# .vscode/preview.yml
+autoOpen: true # 打开工作空间时是否自动开启所有应用的预览
+apps:
+  - port: 8000 # 应用的端口
+    run: yarn start # 应用的启动命令
+    root: ./app # 应用的启动目录
+    name: my-first-app # 应用名称
+    description: 我的第一个 App。 # 应用描述
+    autoOpen: true # 打开工作空间时是否自动开启预览(优先级高于根级 autoOpen)

+ 7 - 0
myApp/www/index.html

@@ -42,6 +42,13 @@
                 <p class="event listening">Connecting to Device</p>
                 <p class="event received">Device is Ready</p>
             </div>
+            <div>
+                <button id = "setLocalStorage">SET LOCAL STORAGE</button>
+                <button id = "showLocalStorage">SHOW LOCAL STORAGE</button>
+                <button id = "removeProjectFromLocalStorage">REMOVE PROJECT</button>
+                <button id = "getLocalStorageByKey">GET BY KEY</button>
+
+            </div>
         </div>
         <script type="text/javascript" src="cordova.js"></script>
         <script type="text/javascript" src="js/index.js"></script>

+ 40 - 4
myApp/www/js/index.js

@@ -18,20 +18,35 @@
  */
 var app = {
     // Application Constructor
-    initialize: function() {
+    initialize: function () {
         document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
+
+
+
+        document.getElementById("setLocalStorage").addEventListener("click", setLocalStorage);
+        document.getElementById("showLocalStorage").addEventListener("click", showLocalStorage);
+        document.getElementById("removeProjectFromLocalStorage").addEventListener
+            ("click", removeProjectFromLocalStorage);
+        document.getElementById("getLocalStorageByKey").addEventListener
+            ("click", getLocalStorageByKey);
+
+        var localStorage = window.localStorage;
+
+
+
+
     },
 
     // deviceready Event Handler
     //
     // Bind any cordova events here. Common events are:
     // 'pause', 'resume', etc.
-    onDeviceReady: function() {
+    onDeviceReady: function () {
         this.receivedEvent('deviceready');
     },
 
     // Update DOM on a Received Event
-    receivedEvent: function(id) {
+    receivedEvent: function (id) {
         var parentElement = document.getElementById(id);
         var listeningElement = parentElement.querySelector('.listening');
         var receivedElement = parentElement.querySelector('.received');
@@ -43,4 +58,25 @@ var app = {
     }
 };
 
-app.initialize();
+app.initialize();
+
+
+function setLocalStorage() {
+    localStorage.setItem("Name", "John");
+    localStorage.setItem("Job", "Developer");
+    localStorage.setItem("Project", "Cordova Project");
+}
+
+function showLocalStorage() {
+    console.log(localStorage.getItem("Name"));
+    console.log(localStorage.getItem("Job"));
+    console.log(localStorage.getItem("Project"));
+}
+
+function removeProjectFromLocalStorage() {
+    localStorage.removeItem("Project");
+}
+
+function getLocalStorageByKey() {
+    console.log(localStorage.key(0));
+}