获取url地址中携带的参数

// 获取url携带的参数
function getParams (name) {
  var search = window.location.search.substring(1)
  if (!search) {
    search = window.location.hash.split('?')[1]
  }
  if (search) {
    var obj = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
    return name ? obj[name] : obj
  }
}

你可能感兴趣的:(vue.js,javascript)