1.antd form表单switch, CheckBox、Switch 默认值设置
{getFieldDecorator('switch', {valuePropName: 'checked', initialValue: true})(<Switch />)}
- ts类型
Event 事件对象类型
常用 Event 事件对象类型:
ClipboardEvent<T = Element> 剪贴板事件对象
DragEvent<T = Element> 拖拽事件对象
ChangeEvent<T = Element> Change 事件对象
KeyboardEvent<T = Element> 键盘事件对象
MouseEvent<T = Element> 鼠标事件对象
TouchEvent<T = Element> 触摸事件对象
WheelEvent<T = Element> 滚轮事件对象
AnimationEvent<T = Element> 动画事件对象
TransitionEvent<T = Element> 过渡事件对象
实例:
handleClick = (e: MouseEvent ) => {}
3.过滤数据
//适用于antd ---table里面dataSource做本地数据的批量删除
_.filter(dataSource, (item: any) => {
return ! _.includes(rowKeySelect, item.key)
})
4.常用qs方法
var prefixed = qs.parse('?a=b&c=d', { ignoreQueryPrefix: true });
// prefixed { a: 'b', c: 'd' }
var prefixed = qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false });
// prefixed 'a=b&a=c&a=d'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
5.mock随机生成数据
‘'name': '@cname', // 中文名称
'key': '@id', //随机id
'id|+1': 88, // 属性值自动加 1,初始值为88
'age|18-28': 0, // 18至28以内随机整数, 0只是用来确定类型
'birthday': '@date("yyyy-MM-dd")', // 日期
'city': '@city(true)', // 中国城市
'color': '@color', // 16进制颜色
'isMale|1': true, // 布尔值
'isFat|1-2': true, // true的概率是1/3
'fromObj|2': obj, // 从obj对象中随机获取2个属性
'fromObj2|1-3': obj, // 从obj对象中随机获取1至3个属性
'brother|1': ['jack', 'jim'], // 随机选取 1 个元素
'sister|+1': ['jack', 'jim', 'lily'], // array中顺序选取元素作为结果
'friends|2': ['jack', 'jim'] // 重复2次属性值生成一个新数组
- less文件中引入别的less文件
@import '../../index.less'
- this.forceUpdate() 页面重新渲染
class App extends Component<> {
public name: any;
......
......
public handle = () => {
this.name = 'zhangsan',
this.forceUpdate()
}
}
9.ts关于定义复杂数据类型的类型
const params: { [propsName: string] : any } = {
index: 1,
num: 20,
order: {},
selector: []
}