Typescript 财产';历史';不存在于类型';VueRouter';在vue ts中
我在一个应用程序中使用typescript vue,我在一个组件中遇到了这个错误,在该组件中,我试图访问传递到路由中的参数,如下所示Typescript 财产';历史';不存在于类型';VueRouter';在vue ts中,typescript,vue.js,vue-router,eslint,typescript-typings,Typescript,Vue.js,Vue Router,Eslint,Typescript Typings,我在一个应用程序中使用typescript vue,我在一个组件中遇到了这个错误,在该组件中,我试图访问传递到路由中的参数,如下所示 properties = getModule(PropertiesModule, this.$store); mounted() { id = this.$router.history.current.params.id; this.properties.getProperty(id); } get months() { r
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;
}
}
这段代码运行得很好,因为据我所知,这不是一种不当行为。但是typescript仍然抛出错误。我试着在下一行使用es lint disable,但它不起作用。我也试着在我的main.ts中给路由器加上any的类型,但效果不太好。
在vue.js中有没有比这更好的访问路由器参数的方法
您可以使用Vue.js中的
$route.params
获取参数
如果您想要获取id
param,这可能会解决
this.$route.params.id