随笔分类 -  react学习

摘要:这个和我上一篇文章是差不多的,只不过这里的组件都不是无状态组件 Test.js import React, { Component } from "react"; import { BrowserRouter as Router, Route, Link } from "react-router-d 阅读全文

posted @ 2020-11-15 03:36 猫头唔食鱼 阅读(92) 评论(0) 推荐(0) 编辑

摘要:1.安装 yarn add react-router-dom 2.引入 BrowserRouter, Route, Link import React from 'react'; import { BrowserRouter as Router, Route, Link } from 'react- 阅读全文

posted @ 2020-11-15 02:43 猫头唔食鱼 阅读(240) 评论(0) 推荐(0) 编辑

摘要:1.安装 npm i mockjs -D 2.新建mockData.js import Mock from 'mockjs' export default Mock.mock('/data','get',{ // 属性 list 的值是一个数组,其中含有 1 到 10 个元素 'list|1-10' 阅读全文

posted @ 2020-11-14 18:27 猫头唔食鱼 阅读(1412) 评论(0) 推荐(0) 编辑

摘要:setState是异步的 如果想操作dom一定要在setState的回调里 例子: 获得ul里li元素的个数 import React, { Component } from 'react'; class Test extends Component { constructor(props) { s 阅读全文

posted @ 2020-11-12 17:10 猫头唔食鱼 阅读(1133) 评论(0) 推荐(0) 编辑

摘要:1.propTypes 子组件规定父组件传过来的值的类型 注意下面注释的地方 import React, { Component } from 'react'; import PropTypes from 'prop-types' // PropTypes 首字母大写 class Child ext 阅读全文

posted @ 2020-11-12 14:39 猫头唔食鱼 阅读(172) 评论(0) 推荐(0) 编辑

摘要:1.安装 yarn add styled-components 2.创建style.js import {createGlobalStyle} from 'styled-components' // 导出的变量要大写开头 export const CreateStyle = createGlobal 阅读全文

posted @ 2020-10-24 15:20 猫头唔食鱼 阅读(241) 评论(0) 推荐(0) 编辑

摘要:App.js import React, { Component } from 'react'; import './style.css' class App extends Component { constructor(props) { super(props); this.state = { 阅读全文

posted @ 2020-10-11 00:47 猫头唔食鱼 阅读(1152) 评论(0) 推荐(0) 编辑

摘要:0.安装Charles中文破解版 1.安装axios yarn add axios 2.引入axios import axios from 'axios' 3.写好json文件test.json ["vue","react","ng"] 4.配置Charles (1)选择工具/本地映射 (2)本地映 阅读全文

posted @ 2020-10-10 00:58 猫头唔食鱼 阅读(178) 评论(0) 推荐(0) 编辑

摘要:方法一:类似vue的写法,标签里定义一个$ref ,然后通过this.refs.xxx获取dom {/* 方法一:类似vue的写法 */} <span ref="test">test</span> // 获取ref只能在componentDidMount里 componentDidMount(){ 阅读全文

posted @ 2020-10-10 00:22 猫头唔食鱼 阅读(636) 评论(0) 推荐(0) 编辑

摘要:1.下载插件后,把插件拖动到谷歌浏览器的扩展程序里。 2.在createStore方法里添加第二个参数(第一个是reducer), window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() import 阅读全文

posted @ 2019-08-01 20:57 猫头唔食鱼 阅读(745) 评论(0) 推荐(0) 编辑

摘要:1.安装redux 2.创建store文件夹,创建store.js 3.创建reducer.js 4.在store.js中引入reducer,并在createStore方法里传入reducer 5.在App.js中,引入store,使用store.getState()方法,获取state 阅读全文

posted @ 2019-07-22 22:46 猫头唔食鱼 阅读(7839) 评论(0) 推荐(1) 编辑

摘要:通过className的true或者false控制元素显示或者隐藏。 App.js App.css 阅读全文

posted @ 2019-07-22 00:47 猫头唔食鱼 阅读(2127) 评论(0) 推荐(0) 编辑

摘要:1.安装 2.引入 3.使用 app.js 阅读全文

posted @ 2019-07-21 11:26 猫头唔食鱼 阅读(245) 评论(0) 推荐(0) 编辑

摘要:fetchjsonp只能发送get请求 阅读全文

posted @ 2019-07-20 19:01 猫头唔食鱼 阅读(1356) 评论(0) 推荐(0) 编辑

摘要:react多选框数组里,需要定义checked属性。 阅读全文

posted @ 2019-07-16 14:55 猫头唔食鱼 阅读(2512) 评论(0) 推荐(0) 编辑

摘要:1.遍历选项,option里的value去掉,把value写到select里 2.onChange方法写到select标签里 阅读全文

posted @ 2019-07-10 11:42 猫头唔食鱼 阅读(8768) 评论(0) 推荐(0) 编辑

摘要:react的input的每一种类型都要绑定onChange事件的,绑定onChange事件要传入事件对象的 react的单选框需要绑定checked属性的 循环input选项的写法: 阅读全文

posted @ 2019-07-10 09:32 猫头唔食鱼 阅读(4031) 评论(0) 推荐(0) 编辑

摘要:1.通过bind获取事件对象获得被点击的dom元素 2.通过箭头函数获取被点击的dom元素(在箭头函数中传入e) 阅读全文

posted @ 2019-07-09 00:27 猫头唔食鱼 阅读(1501) 评论(0) 推荐(0) 编辑

摘要:1.使用bind 2.使用箭头函数 阅读全文

posted @ 2019-07-08 21:30 猫头唔食鱼 阅读(4337) 评论(0) 推荐(0) 编辑

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