[ Vue-ts-错误 ] Property '$router|$store' does not exist on type Vue

项目想引进 typescript ,终于在DEMO 中 把其他东西配好了

但是实际使用的时候,发现在组件里面使用 this.$router 的时候报错

说 这个组件 没有这个属性

log

log
然后我发现 有两种 解决办法,但是我无法说明这是为什么

  • 把 this.$router 改成 this[“$router”],这么写就不会报错了
  • 在 组件中 提前声明 $router 这个东西,然后直接使用 this.$router 就不会报错了

log

坚持原创技术分享,您的支持将鼓励我继续创作!