【问题标题】:Property 'history' does not exist on type 'VueRouter' in vue-tsvue-ts 中的“VueRouter”类型上不存在属性“历史”
【发布时间】:2021-02-08 13:58:19
【问题描述】:

我在应用程序中使用 typescript vue,我有这个错误来自一个组件,我尝试访问像这样传递到路由中的参数

  properties = getModule(PropertiesModule, this.$store);
  mounted() {
    id = this.$router.history.current.params.id;
    this.properties.getProperty(id);
  }
  get months() {
    return this.$store.state.app.months;
  }
  get property() {
    return this.$store.state.properties.property;
  }
}

代码运行得非常好,因为据我所知,这不是违规行为。但打字稿仍然抛出错误。我尝试使用 es-lint disable-next-line 但它不起作用。我还尝试在我的 main.ts 中为路由器指定 any 类型,但效果不佳。 有没有比这更好的方法来访问 vue.js 中的路由器参数?

【问题讨论】:

    标签: typescript vue.js vue-router eslint typescript-typings


    【解决方案1】:

    您可以在 Vue.js 中使用 $route.params 获取参数。

    如果你想得到id 参数,这可能会成功。

    this.$route.params.id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-19
      • 2020-06-26
      • 1970-01-01
      • 2021-01-11
      • 2021-01-10
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      相关资源
      最近更新 更多