枚举类型定义 enum

5/27/2024 ts

# 1.枚举类型定义 enum 【了解】

//订单状态--原生js
const STATE = {
    Pending:"Pending"Success:"Success",
    Fail:"Fail"
}
if(row.state ==STATE.Success){}
1
2
3
4
5
6
7
enum STATE{
     Pending="Pending",
     Success="Success",
     Fail= "Fail"
}
console.log( STATE.Success )  //Success
1
2
3
4
5
6
enum STATE{
    PENDING,  //0
    SUCCESS,   //1
    FAIL      //2
}
console.log(STATE.PENDING)  //0
1
2
3
4
5
6