博客
关于我
配置ts编译文件、vue3.0
阅读量:343 次
发布时间:2019-03-04

本文共 2882 字,大约阅读时间需要 9 分钟。

配置ts编译文件

1. 安装ts编译工具

  • 全局安装typescript和ts-node
  • npm install -g typescript @typescript ts-node
    1. 初始化项目
    2. ts-node -p tsconfig.json

      2. 接口定义

      2.1 接口定义

      interface Animal {    color: string;    height: number;}let a: Animal = {    color: 'gold',    height: 30,};

      2.2 属性接口

      interface Person {    name: string;    age: number;    car?: string; // 可选属性}let liujin: Person = {    name: '刘劲',    age: 18,    // car: '共享单车'};

      2.3 方法接口

      interface LogA {    (a: number, b: number): number;}let add: LogA = (a: number, b: number) => {    return a + b;};let minus: LogA = (a: number, b: number) => {    return a - b;};console.log(add(4, 8));console.log(minus(30, 10));

      2.4 类接口

      interface People {    name: string;    fun(): void;}let p1: People = {    name: '赵丽颖',    fun(): void {        console.log('这是调用接口的方法');    }};console.log(p1);

      2.5 类实现接口

      class Man implements LogB {    name: string = '唐达';    fun(): void {        console.log('这是调用接口的方法');    }}let tangda = new Man();console.log(tangda.name);tangda.fn();

      2.6 接口继承

      interface D extends A {    fn2(): void;}class E implements D {    fn(): void {        console.log('实现了A接口');    }    fn2(): void {        console.log('实现了D接口');    }}let e = new E();e.fn();e.fn2();

      3. 装饰器

      3.1 类装饰器

      function logC(params: any) {    return function(target: any) {        console.log('params:', params);        console.log('target:', target.name);        target.prototype.age = params;        target.prototype.fn = () => {            console.log('该方法被调用了');        };    }}@logC('小王')class Http1 {    name: string | undefined = '哈哈';    age: string | undefined;    fn(): void {    }}let h = new Http1();console.log(h.age);h.fn();

      3.2 属性装饰器

      function logD(params: any) {    return function(target: any, attr: any) {        console.log('params:', params);        console.log('target:', target);        console.log('attr:', attr);        target[attr] = params;    }}@logD('属性装饰器')class Http2 {    name: string | undefined = '属性装饰器';}let h2 = new Http2();console.log(h2.name);

      3.3 方法装饰器

      function logE(params: any) {    return function(target: any, funName: any, desc: any) {        console.log('params:', params);        console.log('target:', target);        console.log('funName:', funName);        console.log('desc:', desc);    }}@logE('方法装饰器')class Http3 {    fn(): void {        var num: number = 20;    }}

      4. Vue 3.0

      4.1 安装

      npm install -g @vue/cli@3.0.0vue create

      4.2 创建项目

      vue create demo3.0

      4.3 项目启动

      npm run serve

      4.4 Vue 3.0新语法

      4.4.1 组件创建

      4.4.2 属性

      4.4.3 方法

      4.4.4 计算属性

      4.4.5 监听

      4.4.6 组件通信

      • 父传子:
      class Child {    @Prop() newname: string | undefined;}
      • 子传父:

      4.5 配置文件

      const vueConfig = {    publicPath: '/',    outputDir: 'dist',    assetsDir: 'static',    indexPath: 'index.html',    devServer: {        proxy: {            '/api': {                target: 'https://example.com',                ws: true,                changeOrigin: true            }        }    }};

    转载地址:http://nxse.baihongyu.com/

    你可能感兴趣的文章
    python系列【仅供参考】:python pip 错误 ModuleNotFoundError: No module named pip._internal 解决办法
    查看>>
    python图像条状状噪声,使用PYTHON PIL从验证码图像中删除背景嘈杂的线条
    查看>>
    Python图像处理:从内存加载jpeg
    查看>>
    python固定后缀(名物化词汇)词频统计:抽取+统计+可视化
    查看>>
    python商品评论数据采集与分析可视化系统 Flask框架 requests爬虫 NLP情感分析 毕业设计 源码
    查看>>
    python商品数据分析可视化系统(带爬虫)京东销售数据分析 计算机毕业设计 源码下载
    查看>>
    python商品库存管理系统 django框架 商品网站 MySQL数据库 源码下载 计算机毕业设计
    查看>>
    Python哪个版本最稳定好用2023.10.19
    查看>>
    Python和黑客技术的渊源
    查看>>
    Python和RF编写接口自动化
    查看>>
    Python和RF编写web自动化
    查看>>
    python和js哪个难_【Python】记一次学习,Python 与 js 在实现闭包时的差异
    查看>>
    python和java哪个更值得学——来自知乎高赞回答
    查看>>
    python和c混合编程 github_在pycharm中使用git版本管理以及同步github的方法
    查看>>
    python命名空间更改_Python模块xml.etree.ElementTree自动修改xml命名空间键
    查看>>
    Python命名中尾随下划线有什么好处?
    查看>>
    Python启动脚本
    查看>>
    Python听写汇总结果
    查看>>
    python吊打Excel?屁!那是你不会用!
    查看>>
    Python合并两张图片 | 先叠透明度再合并 (附Demo)
    查看>>