随笔分类 -  react学习

摘要:react引入本地图片: react引入本地图片, 需要import一个变量,然后在src标签中,绑定这个变量。 需要注意的是: 1.assets文件夹需要放在src文件夹里 2.react的img标签需要 / 结束 react 引入远程图片 react引入远程图片,就像平时一样写img标签一样。s 阅读全文

posted @ 2019-07-05 21:24 猫头唔食鱼 阅读(2275) 评论(0) 推荐(1) 编辑

摘要:1.componentWillMount 2.render 3.componentDidMount 4.componentWillUpdate 5.render 6.componentWillReceiveProps 这个生命周期用在子组件上: 触发时机是: (1)子组件接收了父组件传递的值 (2) 阅读全文

posted @ 2019-06-30 23:25 猫头唔食鱼 阅读(146) 评论(0) 推荐(0) 编辑

摘要:react里子组件不能直接操作父组件的数据。 所以要从父组件传递一个方法给子组件, 子组件获取到该方法后,把子数据传入该方法, 父组件才能获取到子数据 例子: 子组件 Child.js 父组件App.js 使用箭头函数的写法 子组件: 父组件 阅读全文

posted @ 2019-06-23 18:32 猫头唔食鱼 阅读(6904) 评论(0) 推荐(1) 编辑

摘要:删除元素,不要直接操作state里面的值,需要把要更改的值复制一份。 所以使用展开操作符,把数组复制一遍。 阅读全文

posted @ 2019-06-15 22:03 猫头唔食鱼 阅读(5649) 评论(0) 推荐(0) 编辑

摘要:import React ,{Component} from 'react' class App extends Component{ constructor(props){ super(props) this.state = { list:["星期一","星期二","星期三"] } } render(){ return ( ... 阅读全文

posted @ 2019-06-14 00:46 猫头唔食鱼 阅读(2127) 评论(0) 推荐(0) 编辑

摘要:import React, { Component } from 'react' class App extends Component { constructor(props) { super(props) //this.state = {} 定义数据 this.state = { inputValue: "" } } render()... 阅读全文

posted @ 2019-06-12 23:37 猫头唔食鱼 阅读(4084) 评论(0) 推荐(0) 编辑

摘要:react创建组件的方式有两种 1.定义一个类,让这个类继承Component,使用render方法 2.定义一个function,return一些标签 阅读全文

posted @ 2019-06-11 20:33 猫头唔食鱼 阅读(240) 评论(0) 推荐(0) 编辑

摘要:父组件使用子组件,子组件绑定父组件数据 ,子组件用props使用父组件数据 import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; class App extends C 阅读全文

posted @ 2019-01-23 23:46 猫头唔食鱼 阅读(254) 评论(0) 推荐(0) 编辑

摘要:1.属性值绑定state里的数据,不用引号 2.class的绑定用className 3.label中使用for的时候,要改成Htmlfor 4.绑定行内样式,绑定行内样式,需要两个大括号 阅读全文

posted @ 2019-01-17 11:39 猫头唔食鱼 阅读(500) 评论(0) 推荐(0) 编辑

摘要:1.全局安装yarn 2.创建react项目,并用yarn start 运行 3.引入antd/引入antd-mobile 4.在app.js引入button pc端 移动端 5.修改 src/App.css,在文件顶部引入 antd/dist/antd.css pc端 移动端 6.按需加载模块 7 阅读全文

posted @ 2019-01-16 11:45 猫头唔食鱼 阅读(7630) 评论(0) 推荐(0) 编辑

摘要:1.使用bind 也可以这么写: 在constructor里把bind赋值给方法 2.使用箭头函数 也可以这么写 阅读全文

posted @ 2019-01-15 21:58 猫头唔食鱼 阅读(580) 评论(0) 推荐(0) 编辑

摘要:react组件父传子,子组件使用父组件的数据,用props 阅读全文

posted @ 2019-01-15 15:46 猫头唔食鱼 阅读(264) 评论(0) 推荐(0) 编辑

摘要:报这个错,执行下面的命令,然后重新创建项目就可以。 npm cache clean --force 阅读全文

posted @ 2019-01-13 02:12 猫头唔食鱼 阅读(181) 评论(0) 推荐(0) 编辑

摘要:1.全局安装 create-react-app脚手架 【可能需要管理员权限】npm install -g create-react-app 2.创建项目 create-react-app project-name 3.启动项目 cd project-name npm start 监听3000端口即可 阅读全文

posted @ 2018-12-27 15:21 猫头唔食鱼 阅读(126) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示