vue项目使用微信登录获取code

vue yekong 1071℃
      let code = this.getval(window.location.href, 'code')
      that.code = code
      if (code) {
        this.getLogin()
      }
getval (url, name) {
      var reg = new RegExp('(^|\\?|&)' + name + '=([^&|#]*)(\\s|&|#|$)', 'i')
      if (reg.test(url)) return unescape(RegExp.$2.replace(/\+/g, ' '))
      return ''
    },
    getLogin () {
      var that = this
      oauthLogin({ code: that.code }).then((res) => {
        that.userData = res.data
        localStorage.setItem('userData', JSON.stringify(res.data))
        //登录成功后移出code
        window.location.href = window.location.protocol + '//' + window.location.host + window.location.pathname

      })
    }
喜欢 (1)