【问题标题】:How to pass parameter for dynamic route?如何为动态路由传递参数?
【发布时间】:2019-04-24 00:51:12
【问题描述】:

我需要单击转到使用动态路由创建的下一页。它从 vuex 商店获取路由的 ID。当我点击它时,它会给出这个网址

http://localhost:8080/worklist/%7Bname:'worklistDynamic',%20params:%7B%20id:sideSwiperItems[indx+1].id%7D%7D
 ---------------------------------------

这是我的代码:

//html
.side-button-next(@click='switchPage()')
//function
--------------------------
switchPage() {
      this.$router.push(
        `{name:'worklistDynamic', params:{ id:this.sideSwiperItems[this.indx+1].id}}`,
      )
    },
--------------------------
computed: {
sideSwiperItems() {
  return this.$store.state.buildingData.sideSwiperItems
},
indx() {
  if (this.$store.state.buildingData.index === null) {
    return 0
  }
  return this.$store.state.buildingData.index
},

},

【问题讨论】:

    标签: vue.js routing vuex vue-router


    【解决方案1】:

    尝试删除反引号:

    switchPage() {
      let path = { name: 'worklistDynamic', params: { id: this.sideSwiperItems[this.indx + 1].id } }
    
      // or you can write the full path with backticks and interpolation
      let path = `/worklistDynamic/${this.sideSwiperItems[this.indx + 1].id}`
    
      this.$router.push(path)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-19
      • 2023-01-18
      • 2019-08-22
      • 2022-10-18
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多