从url地址上获取参数方法

57 阅读1分钟

可直接使用

  created() {
    this.urlObj = this.getUrlObj();
    console.log(this.urlObj, 11111111111);
  },
  methods: {
    getUrlObj() {
      const obj = {};
      if (!location.href) return obj;
      const str = location.href.split("?")[1];
      if (!str) return obj;
      const arr = str.split("&");
      arr.forEach(item => {
        const list = item.split("=");
        if (list.length === 2) {
          obj[list[0]] = list[1];
        }
      });
      return obj;
    },
    }