vue获取地址栏参数

 

 

 utils.js

export default {
  getUrlKey: function (name) {
    return decodeURIComponent(
      // eslint-disable-next-line no-sparse-arrays,standard/array-bracket-even-spacing
      (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [ , ''])[1].replace(/\+/g, '%20')) || null
  }
}

main.js中注册

 

 

 

import utils from './utils.js'

Vue.prototype.$utils = utils

 

vue方法中获取

 

 

 this.$utils.getUrlKey("参数名")

====================================================

vue本身方法

通过this.$route可以获取输入的值以此来

 

 

 

 

posted @ 2020-12-28 12:02  想学前端的小李  阅读(2312)  评论(0)    收藏  举报