【发布时间】:2018-02-17 04:25:54
【问题描述】:
我尝试在我的 typescript 类组件中访问路由器:
import {Vue} from 'vue-property-decorator'
import Component from 'nuxt-class-component'
import {Getter, Action} from 'vuex-class'
@Component
export default class Login extends Vue {
@Action login
username = ''
password = ''
async submit () {
await this.login({username: this.username, password: this.password})
this.$router.push('/results')
}
}
不幸的是,我得到:
error TS2339: Property '$router' does not exist on type 'Login'.
【问题讨论】:
-
$router 在声明文件中可能是私有的,试试 (
this.$router).push('/results')。如果这有效,那么声明文件是错误的。嗯,你也试过“super.$router”吗?它可能受到保护 -
显然都不起作用。但是这个['router'] 有效。
-
你可以试试这个(this as any)。$router.push()
标签: typescript vue.js