zoukankan      html  css  js  c++  java
  • TypeScript 模块代码的类型描述文件

    安装 jquery
    cnpm install jquery --save

    不以 cdn 的方式引入,而是以模块化的方式引入 jquery
     
    index.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      <script src="./page.ts"></script>
      
    </body>
    </html>

    page.ts

    import $ from 'jquery';
    
    $(function () {
      $('body').html('<div>121212</div>');
      new $.fn.init()
    })

    jquery.d.ts

    // es6 模块化
    declare module 'jquery' {
      interface JqueryInstance {
        html: (html: string) => JqueryInstance
      }
      // 混合类型
      function $(readyFunc: () => void): void;
      function $(selector: string): JqueryInstance;
      namespace $ { // $.fn.init
        namespace fn{
          class init{}
        }
      }
    
      export = $;
    }
  • 相关阅读:
    python之路-javascript
    python之路-css
    python之路-初识前端
    python之路-线程
    python之路-socket
    base64 convert to file
    base64 json
    centos7 hostname
    geoip2 domain
    佛教六度
  • 原文地址:https://www.cnblogs.com/wzndkj/p/13205921.html
Copyright © 2011-2022 走看看