Property'$router' does not exist on type 'Login'.

problem description

vue+typescript+vue-router: has declared global method project compilation error TS2339: Property"$router" does not exist on type "Login".

the environmental background of the problems and what methods you have tried

using this ["$router"] and defining global variables, recompiling will still report the same error

related codes

/ / Please paste the code text below (do not replace the code with pictures)

vuw-shim.d.ts file

declare module "*.vue" {
import Vue from "vue"
  export default Vue;
}

// 
declare module "vue/types/vue" {
  import VueRouter, {Route} from "vue-router"
  import VueI18n from "vue-i18n"
  interface Vue {
    $message: any;
    // $i18n: VueI18n;
    $router: VueRouter;
    $route: Route;
  }
}

call

this.$router.push("/userCenter")

clipboard.png

clipboard.png

Sep.10,2021
Have you solved the problem of

? How to solve it? ask the same question

Menu