zoukankan      html  css  js  c++  java
  • Vue-获取解析地址栏的参数包括中文参数

    getQueryString (name) {
          var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
          var r = window.location.search.substr(1).match(reg)
          if (r != null) {
            return unescape(r[2])
          }
          return null
        },
        getRequest (key) {
          // 获取参数
          var url = window.location.search
          // 正则筛选地址栏
          var reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)')
          // 匹配目标参数
          var result = url.substr(1).match(reg)
          // 返回参数值
          return result ? decodeURIComponent(result[2]) : null
        },

    第一个不能解析中文

    第二个能

    保存到本地

    localStorage.setItem('user_id', this.getQueryString('user_id'))
    localStorage.setItem('roleid', this.getQueryString('roleid'))
    localStorage.setItem('department_id', this.getQueryString('department_id'))
    this.type = this.getQueryString('type')
    this.username = this.getRequest('username')
    this.password = this.getRequest('password')
  • 相关阅读:
    leetcode刷题笔记303题 区域和检索
    leetcode刷题笔记301题 删除无效的括号
    20201208日报
    20201118日报
    20201117日报
    20201116日报
    20201115日报
    20201114日报
    20201113日报
    20201112日报
  • 原文地址:https://www.cnblogs.com/fdxjava/p/11958187.html
Copyright © 2011-2022 走看看