• TypeScript import


    ///<reference path = 'components.ts' />
    namespace Home{
      export class Page{
        user: Components.User = {
          name: '111'
        }
        constructor() {
          new Components.Header();
          new Components.Content();
          new Components.Footer();
        }
      }
    }

    这个 ts 文件有个问题,就是 Components 从哪来,不是很清楚,必须打开其他文件才能追溯到。如果有很多文件,去追溯的话,比较麻烦,不够直观,我们换一种写法

    components.ts

    export class Header {
      constructor() {
        const elem = document.createElement('div');
        elem.innerText = 'This is Header';
        document.body.appendChild(elem);
      }
    }
    
    export class Content {
      constructor() {
        const elem = document.createElement('div');
        elem.innerText = 'This is Content';
        document.body.appendChild(elem);
      }
    }
    
    export class Footer {
      constructor() {
        const elem = document.createElement('div');
        elem.innerText = 'This is Footer';
        document.body.appendChild(elem);
      }
    }

    page.ts

    import { Header, Content, Footer } from './components';
    
    export default class Page{ 
      constructor() {
        new Header();
        new Content();
        new Footer();
      }
    }

    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="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.js"></script>
      <script src="./dist/page.js"></script>
    
      <script>
        require(['page'], function(page){
          new page.default();
        })
      </script>
    </body>
    </html>
  • 相关阅读:
    flume复习(二)
    初级3
    桶排序、计数排序、基数排序的介绍
    Hive编程指南读书笔记(1):
    重写、重载、封装、继承和多态
    Int与Integer的区别
    collect_list/collect_set(列转行)
    Group BY
    H指数
    数据倾斜2
  • 原文地址:https://www.cnblogs.com/wzndkj/p/13180087.html
Copyright © 2020-2023  润新知