【问题标题】:How to pass route params to vuex getter?如何将路由参数传递给 vuex getter?
【发布时间】:2020-08-09 10:11:03
【问题描述】:

我尝试了How to get Vue Router Params in Vuex?,但似乎不起作用。

吸气剂:

getAssetById: state => id => {
      return state.assets.find(asset => asset.id === id)
    }

组件:

<div class="card padding-35 box-shadow ">
        //this on is OK
        {{ assetId }}

        {{ asset }}
      </div>

 computed: {
    assetId() {
      return this.$route.params.id
    },
    asset() {
      //this doesn't work
      return this.$store.getters.getAssetById(assetId)
    }
    asset() {
      //this work
      return this.$store.getters.getAssetById(1)
    }
  }

【问题讨论】:

  • 你得到什么错误?

标签: vue.js vuex vue-router


【解决方案1】:

早该想到的,转换成int解决了问题:

assetId() {
      return parseInt(this.$route.params.id)
    },

【讨论】:

    【解决方案2】:

    觉得需要把return改成this.$store.getters.getAssetById(this.assetId)

    【讨论】:

    • 我有这样的,只是忘了在这里输入,对不起
    猜你喜欢
    • 2019-02-11
    • 2020-07-22
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 2016-09-21
    • 2018-06-20
    • 1970-01-01
    相关资源
    最近更新 更多