I try to access router in my typescript class component:
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')
}
}
Unfortunately, I get:
error TS2339: Property '$router' does not exist on type 'Login'.
Make sure you have the router imported in your main vue file:
This is how I write my components, but I think it is the same.
other answer don't work for me
but the code below works
Shim the vue file and include
$router
:Make a
typings
file calledvue-shim.d.ts
Adjust your shim like this:
now
Vue
(in your case -- this) will have a property of$router
and typescript won't complain.