随笔分类 -  react

摘要:1、React.forwardRef React.forwardRef 会创建一个React组件,这个组件能够将其接受的 ref 属性转发到其组件树下的另一个组件中。 React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返 阅读全文
posted @ 2023-01-08 19:41 男孩亮亮 阅读(187) 评论(0) 推荐(0)
摘要:快速尝试 JSX 在项目中尝试 JSX 最快的方法是在页面中添加这个 <script> 标签: <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> 现在,你可以在任何 <script> 标签内使用 JSX 阅读全文
posted @ 2022-01-11 20:58 男孩亮亮 阅读(112) 评论(0) 推荐(0)
摘要:live-server:https://www.npmjs.com/package/live-server 全局安装: npm install -g live-server 如果不想安装可以使用npx npx live-server --port=3344 从命令行使用 live-server在您的 阅读全文
posted @ 2021-09-28 18:45 男孩亮亮 阅读(1261) 评论(0) 推荐(0)
摘要:1、安装redux、react-redux npm install --save redux react-redux (1) 这里解释一下react-redux、redux 的作用 redux 是状态仓库 react-redux 用于把 react 和 redux 进行关联,使所有的子组件都可以拿到 阅读全文
posted @ 2021-09-14 19:57 男孩亮亮 阅读(545) 评论(0) 推荐(0)
摘要:需求:在axios 响应拦截中,根据响应判断路由跳转 import { createHashHistory,createBrowserHistory } from 'history'; // 引入 createHashHistory // 这里根据路由 hash 或 history 进行调用 cre 阅读全文
posted @ 2021-09-13 15:01 男孩亮亮 阅读(639) 评论(0) 推荐(0)
摘要:适用场景:子组件单独引入使用,不被 Route 组件所包裹,通过this 无法获取到 history、location、match withRouter的作用 作用:是将一个组件包裹进Route里面, 然后react-router的三个对象history, location, match就会被放进这 阅读全文
posted @ 2021-09-13 14:30 男孩亮亮 阅读(315) 评论(0) 推荐(0)
摘要:1、首先我们需要一个高阶组件“RoutingGuard.js”,和router.js(包含所以一级路由的一个数组)文件,在 app.js 中使用 高阶组件 (1)目录如下 2、RoutingGuard.js 高阶组件(这里需要注意的是 ('/' + pathname.split('/')[1]) i 阅读全文
posted @ 2021-09-13 13:41 男孩亮亮 阅读(928) 评论(0) 推荐(0)
摘要:父组件 import React from 'react'; import Tabs from './tabs'; export default class FruitsList extends React.Component { constructor(props) { super(props); 阅读全文
posted @ 2021-03-12 22:37 男孩亮亮 阅读(735) 评论(0) 推荐(0)
摘要:postcss-pxtorem使用方法:https://www.cnblogs.com/liangziaha/p/13636936.html 这里报错 postcss-pxtorem 需要 8. 我以为要使用postcss-pxtorem 8.以上的版本就去看了一下postcss-pxtorem版本 阅读全文
posted @ 2021-03-06 20:47 男孩亮亮 阅读(21454) 评论(2) 推荐(3)