在VueJs中无法通过Vue-Router获取参数

时间:2018-10-13 07:06:27

标签: javascript vue.js vuejs2 vue-router

我有2条与vue-router的路由,其中​​一条接收了参数id

{ 
    path: '/sale/', 
    name: 'other',
    component: ComponentA,
},
{ 
    path: '/sale/option/:id', 
    name: 'close-sale',
    component: ComponentB,
},

事实证明,重定向是直接通过代码完成的,在ComponentA

中进行
this.$router.push({ name: 'close-sale', params: {id: this.id}})

执行此操作时,它会将我重定向到名为close-sale的路径,但是在该路径内,我会获得ID以加载以下格式的数据

data(){
   return {

      id: this.$route.params.id
       ....
   }
 },
  mounted (){
    axios.get('...'+this.id). // undefinied this.id
 },

但是我总是返回id的值。

如果在网址中未显示该ID,我该如何获取?我希望我能理解

0 个答案:

没有答案