Vue-Router+TS无法正常编译

Vue-Router + TS 无法正常编译
以下代码编译报错:
代码


export default class App extends Vue {
    //控制属性
    pageTabIndex:string = "basic";   //Tab索引Key

    //初始化回调
    created() {};

    //个性化事件
    onChangeTab(e) {
        this.pageTabIndex = e;
        let query = merge(this.$route.query, {pageTabIndex:this.pageTabIndex};
        this.$router.push({ path: '', query: query});
    }
}

编译报错

TS2769: No overload matches this call.
  Overload 1 of 2, '(to: RawLocation): Promise<Route>', gave the following error.
    Type 'object' is not assignable to type 'Dictionary<string | (string | null)[] | null | undefined>'.
      Index signature for type 'string' is missing in type '{}'.
  Overload 2 of 2, '(to: RawLocation, onComplete?: ((route: Route) => void) | undefined, onAbort?: ErrorHandler | undefined): void', gave the following error.
    Type 'object' is not assignable to type 'Dictionary<string | (string | null)[] | null | undefined>'.
    43 |         let query = merge(this.$route.query, {pageTabIndex:this.pageTabIndex};
  > 44 |         this.$router.push({ path: '', query: query});
                      |                                       ^^^^^
    45 |     }
    46 | }
    47 | </script>

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/7402575
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:Vue-vue-router解决权限问题
  • 除此之外, 这篇博客: Vue3项目引用TS语法实例中的 vue-router 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
    import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
    import Home from '../views/Home.vue';
    //routes的约束类型是RouteRecordRaw
    const routes: Array< RouteRecordRaw > = [
      {
        path: '/',
        name: 'Home',
        component: Home,
      },
      {
        path: '/about',
        name: 'About',
        component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
      }
    ];
    //createRouter创建router实例
    const router = createRouter({
    //router的模式分为
    	//createWebHistory -- history模式
    	//createWebHashHistory -- hash模式
      history: createWebHistory(process.env.BASE_URL),
      routes
    });
    
    export default router;
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^