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

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

内容简介:简单看了下

简单看了下 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 小结》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

AI极简经济学

AI极简经济学

阿杰伊·阿格拉沃尔、乔舒亚·甘斯、阿维·戈德法布 / 闾佳 / 湖南科技出版社 / 2018-12-1 / 58.00

人工智能正在以不可阻挡的态势席卷全球。无论是iPhone的神经网络引擎、AlphaGo的围棋算法,还是无人驾驶、深度学习……毫无疑问,人工智能正在改写行业形态。如同此前个人电脑、互联网、大数据的风行一般,技术创新又一次极大地改变了我们的工作与生活。 那么,究竟应该如何看待人工智能?在《AI极简经济学》一书中,三位深耕人工智能和决策领域的经济学家给出了清晰的答案。他们以坚实的经济学理论剖析动态,把握......一起来看看 《AI极简经济学》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具