- 博客(4)
- 收藏
- 关注
原创 react hooks
1.useState—数据存储与更新 1.语法 const [state, setState] = useState(initialState) 2.语法说明 state为变量 setState为修改state值的方法 //引入 React 中的 useState Hook。它让我们在函数组件中存储内部 state。 import React, { useState } from 'react'; function Example() { // 声明一个叫 “count” 的 state 变量,
2021-12-01 10:46:19
920
原创 组件三大属性
组件三大属性 state 理解 state 是组件对象最重要的属性,值是一个对象(可以包含多组 key-value) 组件被称为"状态机",通过更新组件的 state 来更新对应的页面(重新渲染组件) 强烈注意 组件render()中的 this 是组件实例对象 组件中自定义方法中的this为 undefined,如何解决? 强制绑定 this,通过函数对象的bind() 箭头函数 状态数据不能直接修改,可通过setState()进行修改 // 错误 this.state.title = 'R
2021-11-08 22:53:56
583
原创 react-函数组件与类组件
函数组件与 class 组件 函数组件 //创建函数式组件 function Mycomponent() { console.log(this); //此处的 this 为 undefined,因为Babel编译后开启了严格模式 return <div>我是用 函数组件 创建的组件,适用于简单场景</div>; } //渲染组件 ReactDOM.render(<Mycomponent />, document.getElementById("root")); /
2021-11-08 22:36:27
611
原创 Vue中Object.defineProperty的使用
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-
2021-08-23 20:27:16
439
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅