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')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM