第二章React全家桶之面向组件编程

news2024/9/21 22:56:23

文章目录

    • 一、组件的基本理解和使用
      • 1-1、函数式组件
      • 1-2、类式组件
    • 二、组件实例的三大核心属性
      • 2-1、state的基本使用
        • 2-2-1、state的总结
      • 2-2、props的基本使用
        • 2-2-1、props的传值与批量传值
        • 2-2-2、对props进行限制
        • 2-2-3、props的简写
        • 2-2-4、类式组件中的构造器与props
        • 2-2-5、函数式组件中使用props
      • 2-3、refs的基本使用
        • 2-3-1、字符串形式的ref
        • 2-3-2、回调函数形式的ref
        • 2-3-3、回调函数形式的ref的调用次数问题
        • 2-3-4、creatRef
    • 三、React的事件处理
    • 四、收集表单数据
      • 4-1、非受控组件
      • 4-2、受控组件
    • 五、生命周期(旧)
    • 六、生命周期(新)
      • 6-1.getDerivedStateFromProps
      • 6-2.getSnapshotBeforeUpdate的使用场景

一、组件的基本理解和使用

组件是 React的一等公民,使用React就是在用组件 组件表示页面中的部分功能 组合多个组件实现完整的页面
功能特点:可复用、独立、可组合

1-1、函数式组件

适用于简单组件(无状态的组件)

<script type="text/babel">
        // 定义函数式组件
        function Demo(){
            return <h2>我是函数定义的组件</h2>
        }
        // 渲染组件到页面
        ReactDOM.render(<Demo/>,document.getElementById('test'))
        // 执行了ReactDOM.render(<Demo/>之后发生了什么
            // 1.React解析组件标签,找到了Demo组件
            // 2.发现组件式使用函数定义的,随后调用该函数,将返回的虚拟dom转为真实dom,随后呈现在页面中

    </script>

1-2、类式组件

适用于复杂组件(有状态的组件)

<script type="text/babel">
        // 创建类式组件
        class Demo extends React.Component {
            render(){
                // 这里的this指向类的实例对象
                console.log(this);
                // render式放在哪里的?Demo的原型对象上,供实例使用
                return  <h2>我是类式组件适用于复杂组件的定义</h2>
            }
        }

        // 渲染组件到页面
        ReactDOM.render(<Demo />,document.getElementById('test'))
        // 执行了ReactDOM.render(<Demo/>之后发生了什么
            // 1.React解析组件标签,找到了Demo组件
            // 2.发现组件式使用函数定义的,随后new出来该类的实例,通过该实例,调用到原型上的render方法
            // 3.将render返回的虚拟dom转为真实dom,渲染到页面上
    </script>

二、组件实例的三大核心属性

2-1、state的基本使用

<script type="text/babel">
        // 定义函数式组件
        class Weather extends React.Component{
           //构造器调用几次? ———— 1次
			constructor(props){
				console.log('constructor');
				super(props)
				//初始化状态
				this.state = {isHot:false}
				//解决changeWeather中this指向问题
				this.changeWeather = this.changeWeather.bind(this)
			}

            render(){
                console.log('render');
				//读取状态
				const {isHot} = this.state
				return <h1 onClick={this.changeWeather}>今天天气很{isHot ? '炎热' : '凉爽'}</h1>
            }
            //changeWeather调用几次? ———— 点几次调几次
			changeWeather(){
				//changeWeather放在哪里? ———— Weather的原型对象上,供实例使用
				//由于changeWeather是作为onClick的回调,所以不是通过实例调用的,是直接调用
				//类中的方法默认开启了局部的严格模式,所以changeWeather中的this为undefined
				console.log('changeWeather');
				//获取原来的isHot值
				const isHot = this.state.isHot
				//严重注意:状态必须通过setState进行更新,且更新是一种合并,不是替换。
				this.setState({isHot:!isHot})
				console.log(this);
				//严重注意:状态(state)不可直接更改,下面这行就是直接更改!!!
				//this.state.isHot = !isHot //这是错误的写法
			}
        }
        // 渲染组件到页面
        ReactDOM.render(<Weather/>,document.getElementById('test'))
        // 执行了ReactDOM.render(<Demo/>之后发生了什么
            // 1.React解析组件标签,找到了Demo组件
            // 2.发现组件式使用函数定义的,随后调用该函数,将返回的虚拟dom转为真实dom,随后呈现在页面中

    </script>

2-2-1、state的总结

1.state是组件对象中最重要的属性,值是对象【可以包含多个key-value的组合】
2.组件呗称为状态机,通过更新组件的state来更新对应页面现实【重新渲染组件】

强烈注意:

  1. 组件中render方法中的this为组件实例。
  2. 组件的自定义方法中的this为undefine,如何解决?
    a:强制绑定this,通过函数对象的bind()
    b:箭头函数
  3. 状态数据,不能直接修改或更新。

2-2、props的基本使用

2-2-1、props的传值与批量传值

<script type="text/babel">
        // 定义函数式组件
        class Person extends React.Component{
            render(){
                console.log(this);
                return (
                    <ul>
                    <li>姓名:{this.props.name}</li>
                    <li>性别:{this.props.sex}</li>
                    <li>年龄:{this.props.age}</li>    
                </ul>
                )
            }
        }
        // 渲染组件到页面
        ReactDOM.render(<Person name="Zhangsan" age="12" sex="男"/>,document.getElementById('test1'))
        ReactDOM.render(<Person name="lisi" age="12" sex="男"/>,document.getElementById('test2'))
        ReactDOM.render(<Person name="wangwu" age="12" sex="男"/>,document.getElementById('test3'))
        // 批量传值
        let info = {name:'四六',age:'23',sex:'女'}
        ReactDOM.render(<Person {...info}/>,document.getElementById('test4'))
    </script>

2-2-2、对props进行限制

<script type="text/babel">
        // 定义函数式组件
        class Person extends React.Component{
            render(){
                return (
                    <ul>
                    <li>姓名:{this.props.name}</li>
                    <li>性别:{this.props.sex}</li>
                    <li>年龄:{this.props.age}</li>    
                </ul>
                )
            }
        }
        // 对props的值进行限制
        Person.propTypes = {
            name:PropTypes.string.isRequired,//限制name必传并且是字符串型
            sex:PropTypes.string,//限制sex是字符串型
            age:PropTypes.number,//限制age是数值型
            speak:PropTypes.func//限制speak是函数型
        }
        // 给props默认值
        Person.defaultProps = {
            name:'未知'
        }
        // 渲染组件到页面
        ReactDOM.render(<Person name="Zhangsan" age={21} sex="男" speak={()=>{}}/>,document.getElementById('test1'))
        // 批量传值
        let info = {name:'李四',age:23,sex:'女'}
        ReactDOM.render(<Person {...info}/>,document.getElementById('test2'))
    </script>

2-2-3、props的简写

<script type="text/babel">
        // 定义函数式组件
        class Person extends React.Component {
            // 对props的值进行限制
            static propTypes = {
                name: PropTypes.string.isRequired,//限制name必传并且是字符串型
                sex: PropTypes.string,//限制sex是字符串型
                age: PropTypes.number,//限制age是数值型
                speak: PropTypes.func//限制speak是函数型
            }
            // 给props默认值
            static defaultProps = {
                name: '未知'
            }

            render() {
                return (
                    <ul>
                        <li>姓名:{this.props.name}</li>
                        <li>性别:{this.props.sex}</li>
                        <li>年龄:{this.props.age}</li>
                    </ul>
                )
            }
        }


        // 渲染组件到页面
        ReactDOM.render(<Person name="Zhangsan" age={21} sex="男" speak={() => { }} />, document.getElementById('test1'))
        // 批量传值
        let info = { name: '李四', age: 23, sex: '女' }
        ReactDOM.render(<Person {...info} />, document.getElementById('test2'))
    </script>

2-2-4、类式组件中的构造器与props

 //构造器调用几次? ———— 1次
			constructor(props){
				console.log('constructor',props);
				super(props)
				//初始化状态
				this.state = {isHot:false}
				//解决changeWeather中this指向问题
				this.changeWeather = this.changeWeather.bind(this)
			}

注意事项:

1.构造器是否接收props,是否传递给super,是否希望在构造器中通过this访问props,就取决于是否使用构造器接收peops,开发中不写构造器,能省略就省略

2-2-5、函数式组件中使用props

<script type="text/babel">
        // 定义函数式组件
        function Person(props){
            return (
                <ul>
                    <li>姓名:{props.name}</li>
                    <li>性别:{props.sex}</li>
                    <li>年龄:{props.age}</li>    
                </ul>
            )
        }
        // 对props的值进行限制
        Person.propTypes = {
            name:PropTypes.string.isRequired,//限制name必传并且是字符串型
            sex:PropTypes.string,//限制sex是字符串型
            age:PropTypes.number,//限制age是数值型
            speak:PropTypes.func//限制speak是函数型
        }
        // 给props默认值
        Person.defaultProps = {
            name:'未知'
        }

        // 渲染组件到页面
        // 批量传值
        let info = {name:null,age:23,sex:'女'}
        ReactDOM.render(<Person {...info}/>,document.getElementById('test2'))
    </script>

注意事项:

1.函数式组件只能使用props,不能使用state和refs

2-3、refs的基本使用

2-3-1、字符串形式的ref

 <script type="text/babel">
        // 创建组件
        class Ref extends React.Component{
            showData = ()=>{
                const {input1} = this.refs
                alert(input1.value)
            }
            showData2 = ()=>{
                const {input2} = this.refs
                alert(input2.value)
            }
            render(){
                return (
                    <div>
                        <input ref="input1" type="text" placeholder="点击按钮展示数据" />  
                        <button onClick={this.showData}>点击展示左侧数据</button>  
                        <input onBlur={this.showData2} ref="input2"  type="text" placeholder="失去焦点展示数据"/>    
                    </div>
                )
            }
        }
        // 展示数据
        ReactDOM.render(<Ref />,document.getElementById('test'))
    </script>

2-3-2、回调函数形式的ref

 <script type="text/babel">
        // 创建组件
        class Ref extends React.Component{
            showData = ()=>{
                const {input1} = this
                alert(input1.value)
            }
            showData2 = ()=>{
                const {input2} = this
                alert(input2.value)
            }
            render(){
                return (
                    <div>
                        <input ref={a=>this.input1 = a} type="text" placeholder="点击按钮展示数据" />  
                        <button onClick={this.showData}>点击展示左侧数据</button>   
                        <input onBlur={this.showData2} ref={a=>this.input2 = a} type="text" placeholder="失去焦点展示数据" /> 
                    </div>
                )
            }
        }
        // 展示数据
        ReactDOM.render(<Ref />,document.getElementById('test'))
    </script>

2-3-3、回调函数形式的ref的调用次数问题

注意:

1.内联函数的形式会造成回调函数调用两次第一次为null,第二次为绑定的属性

<script type="text/babel">
        // 创建组件
        class Ref extends React.Component{
            showData = ()=>{
                const {input1} = this
                alert(input1.value)
            }
            changeWeather = ()=>{
                const {isHot} = this.state
                this.setState({isHot:!isHot})
            }
            saveInput = (a)=>{
                this.input1 = a; 
                console.log('@',a);
            }
            state = {isHot:false}
            render(){
                const {isHot} = this.state
                return (
                    <div>
                        <h2>今天的天气很{isHot ? '炎热' : '寒冷'}</h2>
                        {/*以下内联形式的回调会造成回调执行两次,第一次为null,第二次为绑定的属性标签,先调集展示测试功能,在点击切换天气控制台查看执行次数*/}
                        { /*<input ref={(a)=>{this.input1 = a; console.log('@',a);}} type="text" placeholder="点击按钮展示数据" />*/  }
                        <input ref={this.saveInput} type="text" placeholder="点击按钮展示数据" />
                        <button onClick={this.showData}>点击展示左侧数据</button>   
                        <button onClick={this.changeWeather}>点我切换天气</button>
                    </div>
                )
            }
        }
        // 展示数据
        ReactDOM.render(<Ref />,document.getElementById('test'))
    </script>

2-3-4、creatRef

注意:

1.creatRef创建的自己myRef是专人专用的,只能有一个节点使用这个myRef,如果有多个会被最后一个覆盖

<script type="text/babel">
        // 创建组件
        class Ref extends React.Component{
            myRef1 = React.createRef()
            myRef2 = React.createRef()
            showData = ()=>{
                alert(this.myRef1.current.value)
            }
            showData2 = ()=>{
                alert(this.myRef2.current.value)
            }
          
            render(){
                return (
                    <div>
                        <input ref={this.myRef1} type="text" placeholder="点击按钮展示数据" />  
                        <button onClick={this.showData}>点击展示左侧数据</button>   
                        <input onBlur={this.showData2}  ref={this.myRef2}  type="text" placeholder="失去焦点展示数据" /> 
                    </div>
                )
            }
        }
        // 展示数据
        ReactDOM.render(<Ref />,document.getElementById('test'))
    </script>

三、React的事件处理

注意:

1.通过onXxx属性指定事件处理函数
2.React使用的是自定义(合成事件),而不是使用的原生DOM事件
3.React中的事件是通过事件委托方式处理的(委托给徐建最外层的元素)
4.通过event.target得到发生事件的DOM元素对象

script type="text/babel">
        // 创建组件
        class Ref extends React.Component{
            myRef1 = React.createRef()
            myRef2 = React.createRef()
            showData = ()=>{
                alert(this.myRef1.current.value)
            }
            showData2 = (e)=>{
                alert(e.target.value)
            }
          
            render(){
                return (
                    <div>
                        <input ref={this.myRef1} type="text" placeholder="点击按钮展示数据" />  
                        <button onClick={this.showData}>点击展示左侧数据</button>   
                        <input onBlur={this.showData2}   type="text" placeholder="失去焦点展示数据" /> 
                    </div>
                )
            }
        }
        // 展示数据
        ReactDOM.render(<Ref />,document.getElementById('test'))
    </script>

四、收集表单数据

4-1、非受控组件

<script type="text/babel">
        class Login extends React.Component{
            subFn = (e)=>{
                e.preventDefault()
                const {username,password} = this
                alert(username.value)
            }
            render(){
                return (
                    <form  onSubmit={this.subFn}>
                        用户名:<input  ref={c=>this.username = c} type="text" />    
                        密码:<input ref={c=>this.password = c}  type="password" />  
                       <button>登录</button>
                    </form>
                )
            }
        }
        // 展示数据
        ReactDOM.render(<Login />,document.getElementById('test'))
    </script>

4-2、受控组件

<script type="text/babel">
        class Login extends React.Component{
            state = {
                username:"",
                password:''
            }
            subFn = (e)=>{
                e.preventDefault()
                const {username,password} = this.state
                alert(`您输入的用户名是${username},您输入的密码是${password}`)
            }
            saveUsername = (e)=>{
                this.setState({username:e.target.value})
            }
            savePassword = (e)=>{
                this.setState({password:e.target.value})
            }
            render(){
                return (
                    <form  onSubmit={this.subFn}>
                        用户名:<input onChange={this.saveUsername}  type="text" />    
                        密码:<input onChange={this.savePassword}   type="password" />  
                       <button>登录</button>
                    </form>
                )
            }
        }
        // 展示数据
        ReactDOM.render(<Login />,document.getElementById('test'))
    </script>

五、生命周期(旧)

原理图
在这里插入图片描述

生命周期的三个阶段(旧)
1. 初始化阶段: 由ReactDOM.render()触发---初次渲染
	1.constructor()
	2.componentWillMount()
	3.render()
	4.componentDidMount()
2. 更新阶段: 由组件内部this.setSate()或父组件重新render触发
	1.shouldComponentUpdate()
	2.componentWillUpdate()
	3.render()
	4.componentDidUpdate()
3. 卸载组件: 由ReactDOM.unmountComponentAtNode()触发
	1.componentWillUnmount()

代码演示

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>React生命周期</title>
</head>

<body>
    <div id="test"></div>
    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom 用于支持react操作dom -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入bable,用于将jsx转为js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">
        class Count extends React.Component {
            constructor(props) {
                super(props)
                // 初始化状态
                this.state = { count: 0 }
                console.log('constructor');
            }

            // 组件即将要挂载
            componentWillMount() {
                console.log('componentWillMount');
            }
            // 组件挂载完成的钩子
            componentDidMount() {
                console.log('componentDidMount');
            }
            // 组件将要卸载的钩子
            componentWillUnmount() {
                console.log('componentWillUnmount');
            }
            // 控制组件更新的阀门
            shouldComponentUpdate() {
                console.log('shouldComponentUpdate');
                return true
            }
            // 组件将要更新的钩子
            componentWillUpdate() {
                console.log('componentWillUpdate');
            }
            // 组件更新完毕的钩子
            componentDidUpdate() {
                console.log('componentDidUpdate');
            }
            render() {
                console.log('render');
                const { count } = this.state
                return (
                    <div>
                        <h2>当前求和为:{count}</h2>
                        <button onClick={this.add}>点我加一</button>
                        <button onClick={this.death}>卸载组件</button>
                        <button onClick={this.force}>不更新任何状态,旧强制 更新一下</button>
                    </div>
                )
            }

            // 加一的处理函数
            add = () => {
                const { count } = this.state
                this.setState({ count: count + 1 })
            }
            // 卸载组件的回调
            death = () => {
                ReactDOM.unmountComponentAtNode(document.getElementById('test'))
            }
            // 强制更新按钮的回调
            force = () => {
                this.forceUpdate()
            }
        }

        class A extends React.Component {
            // 初始化状态
            state = {carName:'奔驰'}
            changeCar = ()=>{
                this.setState({carName:'宝马'})
            }
            render() {
                return (
                    <div>
                        <div>我是A组件</div>
                        <button onClick={this.changeCar}>换车</button>
                        <B carName={this.state.carName}/>
                    </div>
                )
            }
        }
        class B extends React.Component {
            
            // 组件将要接收到新的props值
            componentWillReceiveProps(){
                console.log('B--componentWillReceiveProps');
            }
             // 控制组件更新的阀门
             shouldComponentUpdate() {
                console.log('B--shouldComponentUpdate');
                return true
            }
            // 组件将要更新的钩子
            componentWillUpdate() {
                console.log('B--componentWillUpdate');
            }
            // 组件更新完毕的钩子
            componentDidUpdate() {
                console.log('B--componentDidUpdate');
            }
            render() {
                return (
                    <div>我是B组件,接收的车是:{this.props.carName}</div>
                )
            }
        }
        // 展示数据
        ReactDOM.render(<A />, document.getElementById('test'))
    </script>
</body>

</html>

六、生命周期(新)

原理图
与旧的生命周期来比废除了旧生命周期的三个钩子,新提出了两个新的生命周期钩子在这里插入图片描述

生命周期的三个阶段(新)
1. 初始化阶段: 由ReactDOM.render()触发---初次渲染
	1.constructor()
	2.getDerivedStateFromProps 
	3.render()
	4.componentDidMount()
2. 更新阶段: 由组件内部this.setSate()或父组件重新render触发
	1.getDerivedStateFromProps
	2.shouldComponentUpdate()
	3.render()
	4.getSnapshotBeforeUpdate
	5.componentDidUpdate()
3. 卸载组件: 由ReactDOM.unmountComponentAtNode()触发
	1.componentWillUnmount()
重要的勾子
	1.render:初始化渲染或更新渲染调用
	2.componentDidMount:开启监听, 发送ajax请求
	3.componentWillUnmount:做一些收尾工作, : 清理定时器
即将废弃的勾子
	1.componentWillMount
	2.componentWillReceiveProps
	3.componentWillUpdate
现在使用会出现警告,下一个大版本需要加上UNSAFE_前缀才能使用,以后可能会被彻底废弃,不建议使用。

6-1.getDerivedStateFromProps

<script type="text/babel">
        class Count extends React.Component {
            // 构造器
            constructor(props) {
                super(props)
                // 初始化状态
                this.state = { count: 0 }
                console.log('constructor');
            }

            // 若state的值在任何时候都取决于props,那么可以使用getDerivedStateFromProps
            static getDerivedStateFromProps(props,state){
                console.log('getDerivedStateFromProps');
                // return出去的状态旧不会被修改了
                return props
            }

            // 组件挂载完成的钩子
            componentDidMount() {
                console.log('componentDidMount');
            }
            // 组件将要卸载的钩子
            componentWillUnmount() {
                console.log('componentWillUnmount');
            }
            // 控制组件更新的阀门
            shouldComponentUpdate() {
                console.log('shouldComponentUpdate');
                return true
            }
            
            // 组件更新完毕的钩子
            componentDidUpdate() {
                console.log('componentDidUpdate');
            }
            render() {
                console.log('render');
                const { count } = this.state
                return (
                    <div>
                        <h2>当前求和为:{count}</h2>
                        <button onClick={this.add}>点我加一</button>
                        <button onClick={this.death}>卸载组件</button>
                        <button onClick={this.force}>不更新任何状态,旧强制 更新一下</button>
                    </div>
                )
            }

            // 加一的处理函数
            add = () => {
                const { count } = this.state
                this.setState({ count: count + 1 })
            }
            // 卸载组件的回调
            death = () => {
                ReactDOM.unmountComponentAtNode(document.getElementById('test'))
            }
            // 强制更新按钮的回调
            force = () => {
                this.forceUpdate()
            }
        }

        // 展示数据
        ReactDOM.render(<Count />, document.getElementById('test'))
    </script>

6-2.getSnapshotBeforeUpdate的使用场景

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>getSnapShotBeforeUpdate的使用场景</title>
	<style>
		.list{
			width: 200px;
			height: 150px;
			background-color: skyblue;
			overflow: auto;
		}
		.news{
			height: 30px;
		}
	</style>
</head>
<body>
	<!-- 准备好一个“容器” -->
	<div id="test"></div>
	
	<!-- 引入react核心库 -->
	<script type="text/javascript" src="../js/17.0.1/react.development.js"></script>
	<!-- 引入react-dom,用于支持react操作DOM -->
	<script type="text/javascript" src="../js/17.0.1/react-dom.development.js"></script>
	<!-- 引入babel,用于将jsx转为js -->
	<script type="text/javascript" src="../js/17.0.1/babel.min.js"></script>

	<script type="text/babel">
		class NewsList extends React.Component{

			state = {newsArr:[]}

			componentDidMount(){
				setInterval(() => {
					//获取原状态
					const {newsArr} = this.state
					//模拟一条新闻
					const news = '新闻'+ (newsArr.length+1)
					//更新状态
					this.setState({newsArr:[news,...newsArr]})
				}, 1000);
			}

			getSnapshotBeforeUpdate(){
				return this.refs.list.scrollHeight
			}

			componentDidUpdate(preProps,preState,height){
				this.refs.list.scrollTop += this.refs.list.scrollHeight - height
			}

			render(){
				return(
					<div className="list" ref="list">
						{
							this.state.newsArr.map((n,index)=>{
								return <div key={index} className="news">{n}</div>
							})
						}
					</div>
				)
			}
		}
		ReactDOM.render(<NewsList/>,document.getElementById('test'))
	</script>
</body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/729259.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

使用 eKuiper 按需桥接 CAN Bus 数据至 MQTT

CAN Bus 是一种广泛应用于汽车和工业领域的通信协议&#xff0c;它能够让多个设备在同一网络中进行交互。而 MQTT 是一种广泛应用于物联网领域的通信协议&#xff0c;作为一种轻量级的发布-订阅消息传输协议&#xff0c;它有效地促进了机器之间的通信。 通过将 CAN Bus 数据桥…

Vue组件库Element-常见组件-分页

常见组件-Pagination 分页 Pagination 分页&#xff1a;当数据过多时&#xff0c;会使用分页分解数据 具体关键代码如下&#xff1a;&#xff08;重视注释&#xff09; <template><div><!-- Pagination 分页 --><el-pagination background layout"…

Etsy店铺被封的原因是什么?如何防封

ETSY是一个全球知名的在线市场和电商平台&#xff0c;专注于手工艺品、独特商品和创意艺术。它为卖家提供了一个平台来展示和销售自己的手工制品、艺术品、珠宝、家居用品、时尚配饰等各种创意产品。作为一个颇受中国商家青睐的平台&#xff0c;Etsy在账号检测方面也是不亚于亚…

微软MFC技术中消息的分类

我是荔园微风&#xff0c;作为一名在IT界整整25年的老兵&#xff0c;今天来聊聊MFC技术中消息的分类。 微软Windows中的消息虽然很多&#xff0c;但是种类并不繁杂&#xff0c;大体上有3种&#xff1a;窗口消息、命令消息和控件通知消息。 窗口消息 窗口消息是系统中最为常见…

网络安全(黑客)自学路线

一.零基础学习 在网络安全的学习过程中&#xff0c;基础知识是一个绕不过的问题&#xff0c;Web知识本身就非常丰富&#xff0c;覆盖范围也非常广泛。 首先是大家比较熟悉的浏览器、数据库、服务器&#xff1b; 以及由简到难的HTML、JavaScript和CSS、PHP、Java、.net&#…

【Flutter】使用 Drift 实现 Flutter 数据持久化

文章目录 一、前言二、版本信息三、Drift 简介四、如何安装和设置 Drift五、基础使用1. 创建数据库和表2. 插入、查询、更新和删除数据3. 使用事务 六、总结 一、前言 你是否渴望成为 Flutter 的专家&#xff0c;掌握更多的技巧和最佳实践&#xff1f;我们有个好消息要告诉你&…

【vue3】学习笔记--组件通信方式

学习vue3总是绕不开vue2 vue2组件通信方式总结&#xff1a; 1、props&#xff1a;可以实现父子组件&#xff0c;子父组件&#xff0c;甚至兄弟组件通信 2、自定义事件&#xff1a;实现子父组件通信 3、全局事件总线$bus:可以实现任意组件通信 4、pubsub&#xff1a;发布订阅模…

目标检测常用的评价指标

目标检测常用的评价指标 1 IoU&#xff08;Intersection over Union&#xff09;2 GIoU&#xff08;Generalized IoU&#xff09;3 DIoU&#xff08;Distance-IoU&#xff09;4 CIoU&#xff08;Complete-IoU&#xff09;5 EIoU&#xff08;Efficient-IoU&#xff09;6 SIoU7 W…

爬虫入门07——requests中携带cookie信息

爬虫入门07——requests中携带cookie信息 对于需要登陆的网站如果不携带cookie是无法获取我们所需内容的就以查看我在CSDN中的订单为例&#xff0c;在登陆后可以查看到订单信息 而当我们使用Python代码发出请求时&#xff0c;是不携带cookie&#xff0c;因此无法拿到订单相关信…

Flink的状态是否支持任务间共享

背景&#xff1a; 在日常编写代码的过程中&#xff0c;我们经常会在方法内部new很多的其他类对象来进行编码工作&#xff0c;那么对于这种情况怎么让new出来的对象是一个我们特意创建出来的一个mock实例&#xff0c;从而让我们能完全控制new出来的对象的所有行为呢&#xff1f…

【雕爷学编程】Arduino动手做(154)---AFMotor电机扩展板模块3

37款传感器与执行器的提法&#xff0c;在网络上广泛流传&#xff0c;其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块&#xff0c;依照实践出真知&#xff08;一定要动手做&#xff09;的理念&#xff0c;以学习和交流为目的&am…

数模混合项目:模拟跨数字走线注意事项

数模混合项目中&#xff0c;模拟在数字上走线是常有的事&#xff0c;这里需要注意几个点: 1.模拟电源在数字上走线影响不大&#xff0c;但尽量走top metal和AP层。 2.模拟高频线&#xff0c;尤其是时钟&#xff0c;尽量不要在数字上走线&#xff0c;非要走&#xff0c;最好下…

数据总线学习

为啥要数据总线 使用服务化方式发布&#xff0c;业务端和中间件完全解耦合。一处生产&#xff0c;处处消费设计理念。提供用户可定制的托管化通用消费方案&#xff08;如同步mysql到缓存&#xff0c;同步mysql到es&#xff0c;消费mysql到大数据等托管服务&#xff09; 特性 …

python configparser模块常用方法以及常见报错处理

configparser 是 Python 中一个用于处理配置文件的标准库&#xff0c;可以帮助你生成、读取和修改配置文件的内容 1. 生成配置文件 import configparser# 创建一个配置文件对象 config configparser.ConfigParser()# 添加配置项和值 config[Section1] {key1: value1, key2: …

java 科学计算库 Smile

官网 https://haifengl.github.io/ github https://haifengl.github.io/ 简介 统计机器智能和学习引擎&#xff0c;或者简称 Smile&#xff0c;是一个有前途的现代机器学习系统&#xff0c;在某些方面类似于 Python 的 scikit-learn。它是用 Java 开发的&#xff0c;也提供…

私域账号防范手册

微信为什么要养号吗&#xff1f;为什么会被封&#xff1f;是什么原理&#xff0c;怎么解封&#xff0c;这些你的了解吗&#xff1f; 来看看这篇文章&#xff0c;这些都能给你解答。

向日葵远程命令执行漏洞(CNVD-2022-10270) 漏洞复现

为方便您的阅读&#xff0c;可点击下方蓝色字体&#xff0c;进行跳转↓↓↓ 01 漏洞描述02 影响范围03 利用方式05 实战案例06 修复方案 01 漏洞描述 向日葵远程控制是一款面向企业和专业人员的远程pc管理和控制的服务软件。可以在任何有网络的情况下&#xff0c;轻松访问并控制…

Linux命令之nc命令

一、命令简介 nc是netcat的简写&#xff0c;是一个功能强大的网络工具&#xff0c;有着网络界的瑞士军刀美誉。nc命令在linux系统中实际命令是ncat&#xff0c;nc是软连接到ncat。nc命令的主要作用如下&#xff1a; 实现任意TCP/UDP端口的侦听&#xff0c;nc可以作为server以T…

vue3中的包装响应式数据ref、reactive、toRef、toRefs

一、ref Vue 3中拥有一个新的特性叫做ref&#xff0c;它是一个函数&#xff0c;用于包装响应式数据。与Vue 2的data选项不同&#xff0c;ref可以在普通JavaScript中使用&#xff0c;而不仅仅是在Vue组件中。ref可以将普通的JavaScript数据变成响应式的&#xff0c;这意味着当被…

Python接口自动化测试post请求和get请求,获取请求返回值

引言 我们在做python接口自动化测试时&#xff0c;接口的请求方法有get,post等&#xff1b;get和post请求传参&#xff0c;和获取接口响应数据的方法&#xff1b; 请求接口为Post时&#xff0c;传参方法 我们在使用python中requests库做接口测试时&#xff0c;在做post接口测试…