ts
我是一个粉刷匠呀
这个作者很懒,什么都没留下…
展开
-
移动端react-hooks+TS上拉距离顶部一定距离时 改变页面样式
const stickyRef = useRef() //创建一个ref <div ref={stickyRef}></div> //关联ref const [sticky, setSticky] = useState(true); //判断是否固定 通过sticky更换样式 const onScroll = () => { const top = stickyRef.current!.getBoundingClientRect() //获取元素距离顶原创 2021-08-27 15:38:08 · 519 阅读 · 0 评论 -
强类型与弱类型
判断机制:根据是否进行隐式类型转换 强类型 ts js console.log(1 + '1'); //ts js都会进行隐式类型转换 最后打印出来 11 强类型 python print(1 + '1'); //报错原创 2021-06-22 19:20:49 · 49 阅读 · 0 评论 -
静态类型与动态类型
静态类型 以ts为例,如果有语法类型错误,会在编译时就报错 let bool: boolean = true console.log(bool.split());//会报错 动态类型 以js为例,没有编译阶段,如果有语法类型错误,会在运行时报错影响线上 ...原创 2021-06-22 19:12:16 · 73 阅读 · 0 评论 -
TS--从0开始 (六、面向对象编程-1)
类 1、class关键字 class Simple { // 用class创建一个类 } // 使用new实例化 let simple = new Simple() 2、构造函数 constructor class Simple { // 构造函数 constructor() { } // 通常情况下,会把一个类实例化的时候的初始化相关代码写在构造函数constructor中,比如初始化赋值 } let simple = new Simple() 注: 默原创 2021-06-13 13:19:29 · 170 阅读 · 0 评论 -
TS--从0开始 (五、函数深入)
一、函数的标注 function fun(a: string): string { return '' } let fun: (a: string) => string = function (a: string): string { return '' } // 或者可省略不写 let fun: (a: string) => string = function (a) { return '' } // 使用type type callback = (a: str原创 2021-06-13 12:37:40 · 100 阅读 · 0 评论 -
TS--从0开始 (四、高级类型)
一、联合类型 function cssChange(ele: HTMLElement, attr: string, value: number | string): void { //此处的number|string表示value可以为number类型也可以为string类型 } let ele = document.getElementsByTagName('div')[0] cssChange(ele, 'width', '100px') cssChange(ele, 'opacity'原创 2021-06-13 00:19:34 · 304 阅读 · 0 评论 -
TS--从0开始 (三、接口深入-2)
使用接口描述函数 不使用接口时 无法复用 function fun1(x: number, y: number): number { return x + y } function fun2(x: number, y: number): number { return x + y } //无法复用 使用后 interface Func { (x: number, y: number): number } // 使用接口描述函数Func可复用 let fun1: Func =原创 2021-06-12 23:19:38 · 110 阅读 · 1 评论 -
TS--从0开始 (三、接口深入-1)
本章主要为接口中一些属性 先来一个接口 interface Abs { a: number, b: number } let obj: Abs = { a: 100, b: 109 } 一、可选属性 interface Abs { a: number, b: number, c?: string //可选属性 意味着该接口的c可为string或undefined } let obj: Abs = { a: 100, b: 1原创 2021-06-12 00:36:37 · 167 阅读 · 0 评论 -
TS--从0开始(二、TS类型基础)
TS类型 一、基础类型 1.数字 number let num: number = 56 2.字符串 string let str: string = '字符串' 3.布尔值 boolean let isOk: boolean = true 二、空和未定义 注意:这两种类型有且只有一个值,所以在标注一个变量为null或undefined时,就表示这个变量不能被修改了 1.空 null let data1: null = null; 2.未定义 undefined let data2: undefi原创 2021-06-10 23:56:11 · 522 阅读 · 1 评论 -
TS--从0开始(一、学习前准备)
TS–入门级教程 1. 安装环境(官网下载) node + vs-code + git(没有也行) 2. typescript配置 1.使用npm 下载typescript包 npm i -g typescript 2.安装成功后检测tsc版本(如打印tsc版本则成功) tsc -v 3. 创建自己的第一个ts文件 1.空白目录新建文件夹,文件夹下创建src目录,src目录下创建第一个ts文件 ---- 01.ts let str: string = '第一个ts文件' 2.创建新终端原创 2021-06-09 00:11:16 · 558 阅读 · 4 评论