Browse Source

在vue里面内置vconsole

john.hong 2 years ago
parent
commit
979eb8819b
3 changed files with 22 additions and 11 deletions
  1. 1 0
      package.json
  2. 11 11
      public/index.html
  3. 10 0
      src/main.js

+ 1 - 0
package.json

@@ -20,6 +20,7 @@
     "sa-sdk-javascript": "^1.24.13",
     "sa-sdk-javascript": "^1.24.13",
     "uuid": "^9.0.0",
     "uuid": "^9.0.0",
     "vant": "^2.12.50",
     "vant": "^2.12.50",
+    "vconsole": "^3.15.0",
     "vue": "^2.7.14",
     "vue": "^2.7.14",
     "vue-router": "^3.6.5",
     "vue-router": "^3.6.5",
     "vuex": "^3.6.2"
     "vuex": "^3.6.2"

+ 11 - 11
public/index.html

@@ -33,17 +33,17 @@
   <script>
   <script>
     // const debug = window.localStorage.getItem('H5_DEBUG');
     // const debug = window.localStorage.getItem('H5_DEBUG');
     // 开发环境和qa环境 打开debug
     // 开发环境和qa环境 打开debug
-    const debug = /dev-|qa-/.test(window?.injectConfig?.api) || window.location.href.indexOf(8080) > -1;
-    if (debug) {
-      const script = document.createElement('script');
-      script.src = 'https://unpkg.com/vconsole@latest/dist/vconsole.min.js';
-      document.head.appendChild(script);
-      script.addEventListener('load', () => {
-        setTimeout(() => {
-          window.vConsole = new window.VConsole();
-        }, 200);
-      });
-    }
+    // const debug = /dev-|qa-/.test(window?.injectConfig?.api) || window.location.href.indexOf(8080) > -1;
+    // if (debug) {
+    //   const script = document.createElement('script');
+    //   script.src = 'https://unpkg.com/vconsole@latest/dist/vconsole.min.js';
+    //   document.head.appendChild(script);
+    //   script.addEventListener('load', () => {
+    //     setTimeout(() => {
+    //       window.vConsole = new window.VConsole();
+    //     }, 200);
+    //   });
+    // }
     if ( /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) ) {
     if ( /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) ) {
       // https://developers.weixin.qq.com/community/develop/doc/000ae2cb950808f90d8bc415551800
       // https://developers.weixin.qq.com/community/develop/doc/000ae2cb950808f90d8bc415551800
       window.H5_LAUNCH_URL = location.href;
       window.H5_LAUNCH_URL = location.href;

+ 10 - 0
src/main.js

@@ -1,6 +1,16 @@
 import Vue from 'vue';
 import Vue from 'vue';
 import VueRouter from 'vue-router';
 import VueRouter from 'vue-router';
+import VConsole from 'vconsole';
 
 
+
+// 或者使用配置参数来初始化,详情见文档
+// 开发环境和qa环境 打开debug
+const debug = /dev-|qa-/.test(window?.injectConfig?.api) || window.location.href.indexOf(8080) > -1;
+if (debug) {
+  window.vConsole = new VConsole(
+    // { theme: 'dark' }
+  );
+}
 import './plugins/install';
 import './plugins/install';
 import App from './App.vue';
 import App from './App.vue';
 import store from './store/index.js';
 import store from './store/index.js';