
react
冰魂破
这个作者很懒,什么都没留下…
展开
-
React中的webpack如何配置less
1. 暴露配置文件npm run eject如果执行 npm run eject报错 小心是.git隐藏文件 需要删除在执行命令2. 下载loadernpm install less less-loader说明:推荐使用的方法--不用考虑less-loader版本的问题3. 修改webpack.config.js修改前:constcssRegex=/\.css$/;修改后: constcssRegex=/\.css|less$/;4. 新...原创 2021-07-21 22:43:46 · 1115 阅读 · 1 评论 -
react基础之--样式设置
1、行内样式设置<p style = {{color:'red', fontSize:'14px'}}>{this.state.name}</p>2、以对象的形式 将样式抽离出来 进行设置import React from 'react'const nameStyle = { fontSize: '20px', color: '#000', fontWeight: 'bold',}export default class Child2 ext..原创 2020-12-03 20:01:18 · 601 阅读 · 0 评论 -
react基础之--事件绑定的写法
1、 在调用的时候使用 bind 绑定 thisimport React from 'react'export default class Child2 extends React.Component{ constructor(props){ super(props) this.state = { name:'aaa' } } handleName(){ this.setState({ name:'ks' }) }原创 2020-12-03 19:52:35 · 159 阅读 · 1 评论 -
react基础之--setState的三种写法
修改state的值不能直接去修改 state 的值,否则数据无法驱动关联,需要使用 setState,setState 方法接收一个参数,参数为一个对象,类似于小程序原生的 setData。// 错误方式this.state.name = 'ks'// 正确方式this.setState({ name: 'ks' })存在props值的修改state的值因为更新的 props 和状态是异步的。这里,我们根据这些 props 更新状态。// 错误方式this.setS...原创 2020-12-03 14:02:04 · 1639 阅读 · 1 评论 -
react基础之--子组件向父组件传值
在父组件中定义一个函数,该函数用于处理传递过来得值(比如用于修改父组件中state得数据) 在子组件调用部分通过属性绑定得形式绑定该函数(在子组件中就可以通过this.props.属性名就可以拿到该函数) 在子组件中绑定触发传值得事件比如点击事件,在事件处理函数中通过this.props.属性名()调用父组件中定义得方法 就可以在父组件中拿到传递过来得值进行使用具体代码如下:父组件代码:import React from 'react'export default class Hom.原创 2020-12-02 20:30:07 · 1119 阅读 · 0 评论 -
react基础之--父子间通信 props传值 以及prop-types的基本使用
步骤:1.父组件调用子组件时传入属性2.子组件直接通过this.props.属性名 即可拿到父组件传过来的值父组件代码:import React from 'react'import Child from '../components/child1'export default class Home extends React.Component{ constructor(props) { super(props) this.state =.原创 2020-12-02 19:58:35 · 1049 阅读 · 0 评论 -
react基础之-- 列表循环
在jsx语法中,循环渲染是利用数组的遍历 map() 方法返回一个集合。遍历时必须有唯一索引 key 提高遍历的效率。一个元素的 key 最好是这个元素在列表中拥有的一个独一无二的字符串,万不得已可以使用 index。import React from 'react'export default class Home extends React.Component{ constructor(props) { super(props) this.st.原创 2020-12-01 23:36:25 · 1884 阅读 · 0 评论