
Typescript 学习记录
Typescript 学习记录
张婷张婷呀
这个作者很懒,什么都没留下…
展开
-
(1)ts安装与运行
1. 环境安装(1)全局安装typescriptnpm install -g typescript(2)检查是否安装完成tsc -v tsc的作用:将ts转化为浏览器或node.js能识别的js代码ts代码运行原创 2020-11-02 16:18:36 · 739 阅读 · 0 评论 -
(5)vue+ts
1.vue+ts项目脚手架搭建(1)安装vue脚手架 npm i -g @vue/cli如果报错A complete log of this run can be found in:需要全局安装更新npmnpm install npm -g再运行npm i -g @vue/cli即可(2)创建vue项目原创 2020-11-10 11:14:51 · 164 阅读 · 0 评论 -
(4)类
1. 创建对象(1)js写法function testClass(name,age){this.name=namethis.age=age}testClass.prototype.test1=function (){console.log(this.name,this.age)}//调用let t=new testClass('张婷',19)t.test1()//张婷 19t.namet.age(2)ts写法class testClass{name:string;//成员原创 2020-11-09 11:51:04 · 2280 阅读 · 0 评论 -
(3)函数
1.函数定义在ts中函数有返回值,要定义返回值的类型,当函数没有返回值时,则用void来定义//有返回值function testMethod():string{return 'hhhhh'} let testMethod:number = function(){return 11}//无返回值function testMethod():void{····} let testMethod:void = function(){····}2.函数参数(1)形参实参一般用法/原创 2020-11-03 11:58:46 · 124 阅读 · 0 评论 -
(2)ts数据类型
1.ts数据类型总览ts包含js原有的数据类型,并且在js基础上新增了几种数据类型2.数据类型的定义(1)常见数据类型let type1:number=1//number:只能为数字类型let type2:boolean=true//boolean,只能为true和falselet type3:string='字符串呵呵'//string,只能为字符串(2)数组(Array)数组有两种定义方式// 在元素类型后面加上[],数组每个元素都为numberlet arr: number[]原创 2020-11-02 17:57:05 · 682 阅读 · 0 评论 -
如何配置vscode自动编译ts文件生成js文件
(1)生成tsconfig.json 配置文件tsc --init(2)修改tsconfig.json 文件配置outDir属性即为输出的js文件的路径(3)设置监听/运行在vscode中按 mac: Command+ ⬆️ + B ; windows: Ctrl + Shift + B选择监听后每次保存将会自动更新对应文件夹中js的内容...原创 2020-11-02 16:19:36 · 1413 阅读 · 0 评论