Home  >  Q&A  >  body text

javascript - How does vue get the parameter value in the url?

1. Create the geturlpara.js file

2. Register the global method in main.js
import geturlpara from './geturlpara.js'
Vue.prototype.$geturlpara = geturlpara
3.var mid = this.$geturlpara.getUrlKey("mid")

After running, the console reports an error

我想大声告诉你我想大声告诉你2712 days ago1189

reply all(3)I'll reply

  • 阿神

    阿神2017-05-19 10:38:06

    Write step 3 into the vue component file to get the parameter values

    reply
    0
  • 某草草

    某草草2017-05-19 10:38:06

    There is a url parser in nodejs, and there is a .route attribute in
    vue instance, both of which can get the link parameters.
    If you can’t encapsulate a js method, you can also do it, or directly search on Baidu, there are a lot of ready-made ones
    Your error is still xxx.[ 1] problem, if the returned array is empty or [''], your [1] === undefined
    undefined.replace() will naturally report an error

    reply
    0
  • 高洛峰

    高洛峰2017-05-19 10:38:06

    If you are using vue-router the documentation is here Properties of the routing information object

    const routes = [
      {path : '/portfolio/:year/review', component : Portfolio }
    ];

    Get it like this

    this.$route.params.year
    this.$route.query.id

    reply
    0
  • Cancelreply