Vue + TypeScript 重构 vue-admin-element 小结

栏目: JavaScript · 发布时间: 7年前

内容简介:简单看了下

简单看了下 typescript 官网 的语法,就想借助一个项目实战下。这里选用了 vue-admin-element

附上源码地址: vue-element-admin-ts ,欢迎 star 或 fork

遇到的问题及解决方案

  • Q: error TS7017: Index signature of object type implicitly has an 'any' type

    A: https://stackoverflow.com/que...

    或者在 tsconfig.json 文件的 compilerOptions 选项中添加

    "noImplicitAny": false
  • Q: error TS2339: Property 'webkitURL' does not exist on type 'Window'

    A: https://stackoverflow.com/que...

    interface Window {    
        webkitURL?: any; 
    } 
    declare var window: Window;
  • Q: Property 'context' does not exist on type 'NodeRequire'.

    A: https://github.com/rails/webp...

    npm i -D @types/webpack-env
  • Q: 'this' implicitly has type 'any' because it does not have a type annotation

    A: https://stackoverflow.com/que...

  • Q: 导入 .vue 时,为什么会报错,即使所写的路径并没有问题?

    A: 在 TypeScript 中,它仅识别 js/ts/jsx/tsx 文件,为了让它识别 .vue 文件,我们需要显式告诉 TypeScript,vue 文件存在,并且指定导出 VueConstructor:

    declare module '*.vue' {
      import Vue from 'vue'
      export default Vue
    }
  • Q: TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.

    A: 空的数组添加数据的时候,会有这个提示,解决方案: https://github.com/Microsoft/...

  • Q: Property 'basePath' has no initializer and is not definitely assigned in the constructor.

    59 |   @Prop({required: true, default: {}}) public item: Route;
        60 |   @Prop({default: false}) public isNest: boolean;
      > 61 |   @Prop({default: ''}) public basePath: string;
  • A: https://github.com/kaorun343/...
  • Q: Object is possibly 'undefined'.

    A: https://stackoverflow.com/que...

  • Q: Property '$refs' does not exist on type 'Element | Element[] | Vue | Vue[]'. Property '$refs' does not exist on type 'Element'.

    A: https://github.com/vuejs/vue-...

    https://juejin.im/post/5bd698...

    https://www.leevii.com/2018/1...


以上所述就是小编给大家介绍的《Vue + TypeScript 重构 vue-admin-element 小结》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Mechanics of Web Handling

The Mechanics of Web Handling

David R. Roisum

This unique book covers many aspects of web handling for manufacturing, converting, and printing. The book is applicable to any web including paper, film, foil, nonwovens, and textiles. The Mech......一起来看看 《The Mechanics of Web Handling》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

随机密码生成器
随机密码生成器

多种字符组合密码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具