Parcourir la source

获取url参数

liyongli il y a 3 ans
Parent
commit
0764475441
4 fichiers modifiés avec 18 ajouts et 18 suppressions
  1. 1 0
      src/appMinxin/getList.js
  2. 1 1
      src/components/tabs.vue
  3. 15 16
      src/utils/utils.js
  4. 1 1
      src/view/live/index.vue

+ 1 - 0
src/appMinxin/getList.js

@@ -23,6 +23,7 @@ export default {
         topic_name: title,
         season,
       }).then(x => {
+        x = x || {};
         this.allList = {
           read: x.total_pv || 0,
           talk: x.total_comment || 0,

+ 1 - 1
src/components/tabs.vue

@@ -75,7 +75,7 @@ export default {
         if (this.$route.name !== "secondTopic") return v.id == id;
         else if (!select) return i === 0;
         else return v.id == select;
-      });
+      }) || {};
 
       this.routerData = {
         title: Data.title,

+ 15 - 16
src/utils/utils.js

@@ -1,21 +1,20 @@
 function getUrl(key) {
-    // hash模式下 路由参数
-    let params = location.href.split("?");
-    params = params.length ? params[params.length - 1] : "";
-    params = params.split("#")[0];
-    params = params.split("&");
+  // hash模式下 路由参数
+  let params = location.href.split("?");
     const obj = {};
-    params.map(v => {
-        if (v) {
-            let data = v.split("=");
-            obj[data[0]] = decodeURIComponent(data[1])
-        }
-    })
-    if (key) return obj[key]
-    return obj
+  for (let i = 1; i < params.length; i++) {
+    const v = params[i].split("#")[0].split("&");
+    v.map(val => {
+      if (val) {
+        let data = val.split("=");
+        obj[data[0]] = decodeURIComponent(data[1]);
+      }
+    });
+  }
+  if (key) return obj[key];
+  return obj;
 }
 
-
 export default {
-    getUrl
-}
+  getUrl,
+};

+ 1 - 1
src/view/live/index.vue

@@ -34,7 +34,7 @@ export default {
     },
   },
   mounted() {
-    let q = this.$route.query;
+    let q = this.$route.query || {};
     q.douyin === "true" ? (this.douyin = true) : (this.douyin = false);
     q.kuaishou === "true" ? (this.kuaishou = true) : (this.kuaishou = false);
     if (!this.douyin && !this.kuaishou) return;