Once stepped vue + ts pit diary

Wrote an event in which the method vue time to write such a routing jump method probably as follows:

 goBack1() {
           console.log(this);
           this.$router.back();
 }
Under normal circumstances, as long as you use a vue-router no problem, but because of the type of inspection is very strict, so even if ultimately be used in the TS. But will appear on the compiler
Property '$ router' does not exist on type '{goBack1 (): void;}' this problem, check the prototype chain discovery method is beginning just think there is a router problem with this method, but this is actually refs. the method calls for some time as being given, the problem lies in this top, he points to the vuecomponent this type, our approach is really a void return, any type, so long as the change
((this as any).$router).back();
For this conversion will be able to carry out a

Guess you like

Origin www.cnblogs.com/llcdbk/p/11908384.html