zoukankan      html  css  js  c++  java
  • 解析vue项目中的 url 的 query 数据

    // 用于解析vue项目中的 url 的 query 数据
    // 如是 hash 模式,取 location.hash,如 #/xxx?a=1&b=2
    // 如是 history 模式,取 location.search
    function parseQuery () {
      const str = location.search || location.hash || ''
      const [hash, query] = str.split('?')
      const result = { hash, query: {} }
      if (query) {
        const strs = query.split('&')
        for (let i = 0; i < strs.length; i++) {
          const [key, value] = strs[i].split('=')
          result.query[key] = value
        }
      }
      return result
    }

    使用的时候

    function checkLogin () {
      if (!sessionStorage.loginToken) {
        const { hash, query } = parseQuery()
        if (query.token) {
          window.sessionStorage.loginToken = query.token
          window.sessionStorage.loginUserId = query.userId
          window.sessionStorage.loginTicket = query.ticket
    
          let routePath = ''
          const pushQuery = removeAuthInfoFromQuery(query)
          if (hash) {
            // hash 模式
            routePath = hash.slice(hash.indexOf('#') + 1)
          } else {
            // history 模式
            routePath = location.pathname
          }
          router.replace({
            path: routePath,
            query: pushQuery
          })
        } else {
          getToken()
        }
      }
    }
  • 相关阅读:
    Spring MVC异常处理
    tomcat bio nio apr 模式性能测试
    事务中处理异常
    Cookie和Session
    SpringMVC表单标签简介
    <mvc:annotation-driven/>
    真机调试
    Xcode 9,真机测试,App installation failed
    KONE-FLOW Vistor Key
    cordova 内部API 用ssl https,报错
  • 原文地址:https://www.cnblogs.com/yixiancheng/p/15798212.html
Copyright © 2011-2022 走看看