【问题标题】:vue3 typescript question. what type is lazy-loading vue-router?vue3 打字稿问题。什么类型的延迟加载vue-router?
【发布时间】:2021-07-02 20:45:56
【问题描述】:
export default {
  path: '/about',
  name: 'About',
  // route level code-splitting
  // this generates a separate chunk (about.[hash].js) for this route
  // which is lazy-loaded when the route is visited.
  component: (): Promise<any> => import(/* webpackChunkName: "about" */ '../../views/About.vue'),
};

我正在使用 Vue3 & vue-router & eslint air-bnb,

eslint 检查说我需要 设置正确的类型,我如何检查类型以及应该填写什么类型以避免 eslint 检查?非常感谢

【问题讨论】:

    标签: javascript typescript types vue-router vuejs3


    【解决方案1】:

    正确的返回类型是Promise&lt;RouteComponent&gt;

    import { RouteComponent } from "vue-router";
    
    export default {
      path: '/about',
      name: 'About',
      component: (): Promise<RouteComponent> => import('../../views/About.vue'),
    };
    

    【讨论】:

    • RouteComponent 未在vue-router 中定义
    • @Chu It does exists,但仅在 vue-router next (v4.x) 上,我认为这是 OP 使用的版本,因为他提到他正在使用 Vue 3。您可能正在使用 vue- Vue 2 的路由器 v3
    猜你喜欢
    • 2022-06-20
    • 2018-03-15
    • 2022-01-19
    • 2021-05-12
    • 2019-03-13
    • 2021-04-23
    • 2020-02-01
    • 2012-08-07
    • 1970-01-01
    相关资源
    最近更新 更多