
React
lllomh
私信邮箱: lllomh@qq.com 网站: https://www.lllomh.com/
展开
-
Nextjs 设置网页meta等
放里面就行 . 在_app.js 中。原创 2025-01-02 06:29:21 · 184 阅读 · 0 评论 -
Nextjs打包类型检查报错ype error: Property ‘card_list‘ does not exist on type(已解决)
这样就行了. 打包类型检查就可以通过, 本篇整合来自 群友:@年轻人不要太年轻。那么在 声明类型的时候 使用。原创 2024-01-03 13:38:24 · 698 阅读 · 0 评论 -
Nextjs服务端中存入cookie 全站使用然后跳转getServerSideProps
【代码】Nextjs服务端中存入cookie 全站使用然后跳转getServerSideProps。原创 2024-04-02 12:43:57 · 385 阅读 · 0 评论 -
React 中报Type error: Could not find a declaration file for module ‘qs‘.(已解决)
如果你的项目中没有tsconfig.json文件,你可以创建一个。ts项目引入qs 比如 nextjs 或者reactjs。确保你的tsconfig.json文件中有以下设置。原创 2023-10-12 14:28:08 · 1232 阅读 · 0 评论 -
关于 useEffect(() => { handlePostRequest(); }, []);执行2次(已解决)
reactStrictMode 设置为 false 就可以了.记得重新run dev。执行2次问题. 这个在开发环境出现的时候,关闭下 next.config.js 中的。原创 2023-10-11 16:39:39 · 476 阅读 · 0 评论 -
next.js报错Error: React.Children.only expected to receive a single React element child.(已解决)
next.js 报错Error: React.Children.only expected to receive a single React element child.这个只要把里面的 Link 标签换 a 就可以了, 效果都一样的, Link标签最后也是会渲染成a标签的原创 2021-11-11 16:20:57 · 1692 阅读 · 0 评论 -
nextjs代理转发fetch请求封装
原创 2022-01-01 15:57:24 · 5622 阅读 · 0 评论 -
next.js引入 cookie 报错
引入 cookie 报错写在要用的方法下面就可以了 handleClickSubmit= async ()=>{ const [setCookie] = useCookies(["user"]) let param={ reqName:'P_LOGIN', email:this.state.username, password:this.state.passw..原创 2021-09-07 17:22:55 · 1167 阅读 · 0 评论 -
next.js The old API will be supported in all 16.x releases, but applications using it should migrate
react-dom.development.js:67 Warning: Legacy context API has been detected within a strict-mode tree.The old API will be supported in all 16.x releases, but applications using it should migrate to the new version.Please update the following components:原创 2021-09-06 17:57:29 · 1060 阅读 · 0 评论 -
React中WebSocket使用以及服务端崩溃重连
我这是即使通知推送,服务端用的node:完整版demo 请狠狠的点这里http://download.lllomh.com/cliect/#/product/JB06452810852671创建 node端index.js, node index.js 执行我这是 去拿 接口的数据再转发给前端var ws = require('nodejs-websocket');var Axios =require('axios')var server = ws.createServer(...原创 2021-03-01 09:47:55 · 2777 阅读 · 0 评论 -
react-image-gallery 加入视频图片混合显示
特别是在做商城项目的时候,会有需要带有视频跟图片一起的幻灯箱展示方式,如下:幻灯使用地址https://blog.youkuaiyun.com/lllomh/article/details/103958205这个灯箱的用法是传入数组来做的,上面是大图,下面是导航条图片!正常情况下直接在这里增加 一个对象把original地址换成视频连接就好就行了.但是会出现渲染在img中,报错。这就要修改插件了。方式就是,在这里面增加一个type字段等于 video, 然后在插件里面渲染的地方去..原创 2020-12-02 10:01:43 · 1832 阅读 · 1 评论 -
React中实现倒计时功能根据接口防止刷新
react中实现根据接口返回的毫秒数,显示倒计时:还剩于00分00秒import React,{ Component } from 'react';class OrderDetail extends Component{ constructor(props){ super(props) this.state={ msg:"" } } timeTransition = (ms) => {原创 2020-10-15 17:02:02 · 1585 阅读 · 0 评论 -
React监控url参数值变化后执行(componentWillReceiveProps最佳替代方案)
在class 外面 定义: const TypeChnage=(props)=>{ console.log(props.type,'ssssssssssssssssssssssss') constinit=()=>{ console.log('cccccccccc') }; useEffect(()=>{ props.init(); },[props.type]); returnnu...原创 2022-10-03 08:47:38 · 1046 阅读 · 0 评论 -
React.js组件拆分js文件
利用 react 自带的 懒加载:const Home =React.lazy(()=>import('../pages/home'))const Product =React.lazy(()=>import('../pages/product'))导入组件用这种方式 在入口index,js 中:ReactDOM.render( <Provider store={store}> <React.Suspense fallback={&l.原创 2020-09-15 13:58:06 · 1615 阅读 · 0 评论 -
React-next.js组件中[已解决]react异常:Can‘t perform a React state update on an unmounted component
报错如下图:Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.原因:r.原创 2022-07-04 12:10:47 · 792 阅读 · 0 评论 -
React-next.js中获取不到window属性问题ReferenceError: window is not defined
在componentDidMount里面获取即可 componentDidMount() { this.scrolltops() console.log('window.innerHeight', window.innerHeight); } scrolltops=()=> { window.addEventListener('scroll', () => { if(document.原创 2022-09-04 13:50:09 · 3281 阅读 · 0 评论 -
React-next.js中渲染变量的坑报错Error: React.Children.only expected to receive a single React element child.
这个问题再 react 前端渲染的时候是没有问题的,但是在next的项目中会出现:在字段中类型不一样的时候,如果你写的是:会导致报出奇怪的错误,很难定位的那种如图:会直接报前面 setState 的错误,确实让人摸不着头脑。--------分割线------------------------------后来发现,是类型的问题,这render 好像只能渲染字符串的数据:于是乎改成:转为字符串成功,不再报之前的错误了!至此:解决该问题...原创 2020-11-01 17:47:43 · 2359 阅读 · 0 评论 -
React 中 axios 请求All并行处理,VUE一样适用
多个请求要等全部都请求玩再做处理实现,这有时候是会用到的.这里记录下先上代码:import axios from 'axios'// 对all 的封装:const $all = function (url, params) { requestNames = params.requestName console.log(params.requestName) return axios({ url:url, .原创 2020-09-01 11:56:09 · 1639 阅读 · 0 评论 -
React apache 静态文件缓存实现(亲测可用)
在. .haccess 中配置直接添加设置了Cache-Control 会覆盖Expires的过期时间<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|woff|js|css|swf)$"> Header set Cache-Control "max-age=31536000" FileETag MTime Size</FilesMatch><IfModule expires_module> ...原创 2020-10-02 03:29:51 · 1558 阅读 · 0 评论 -
react-image-gallery幻灯组件跟react-image-lightbox灯箱组件结合记录
这2个单独各自的实例,前面几篇都有详细记录。react-image-gallery:https://blog.youkuaiyun.com/lllomh/article/details/103958205react-image-lightbox :https://blog.youkuaiyun.com/lllomh/article/details/103896313这里记录配置幻灯片定位灯箱的配置问题! 就是滑到哪个幻灯片,点击该幻灯图片就出现灯箱,并且从该图片开始展示在react-image-gallery中利用原创 2020-08-10 10:01:06 · 1666 阅读 · 0 评论 -
react 列表循环中单个自由控制里面的元素disabled
记录下情况:需求是这样的:因为整个都是循环出来的, 这控制又是用的变量!伪代码: <Select disabled={!this.state.isOpens['ids'+index]?true:false}做法就是利用index 去匹配存值:定义 全 变量: constructor(props) { super(props); this.state = { isOpens:{},这是点击触发的: .原创 2022-08-01 10:17:02 · 1021 阅读 · 0 评论 -
react-keep-alive 缓存使用
今天来说说,react 的路由缓存,这个在react 中很少有实质性可用的资料!此篇记录一下demo请狠狠的戳这里¥ http://download.lllomh.com/cliect/#/product/J804099672377354demo 请狠狠的戳这里 c https://download.youkuaiyun.com/download/lllomh/12684925导入 之后 :import { Provider, KeepAlive,} from 're...原创 2021-05-02 00:19:18 · 1730 阅读 · 0 评论 -
React.js禁止浏览器自动填充解决方案[亲测可用]
网上有很多关于这个问题的资料,什么autocomplete = off 啦 等等啦 , 什么autocomplete =‘new-password’啦。可惜都是统统不靠谱的,可能是更新的问题,还是为何,不知道为何这么多无效的资料。我这记录下载react中可用的解决方案,估计vue或者input也适用:我这是用的antd:就是在 form 中最上面 加一个 不显示的 input。加上可读属性!<Form.Item label=" " className={`list_item...原创 2020-09-02 10:43:47 · 3261 阅读 · 0 评论 -
React.js登录权限控制实现demo[亲测可用]
react 在项目中如果遇到有些页面是登录之后才有权限访问的情况如何处理?本文记录一下。带axios登录请求封装token跟redux封装demo请的戳这里狠狠:http://download.lllomh.com/cliect/#/product/J702699872528330一:目录结构比如有四个页面组件,error home index login 假定 home是要登录以后才能访问的话。怎么做呢?先上整体目录结构吧二:路由router1,在路由中 分成 map 去...原创 2020-07-08 11:29:58 · 2681 阅读 · 1 评论 -
react-router-dom5.0的路由拦截(路由守卫)实现
react不同于vue,通过在路由里设置meta元字符实现路由拦截。在使用 Vue ,框架提供了路由守卫功能,用来在进入某个路有前进行一些校验工作,如果校验失败,就跳转到 404 或者登陆页面,比如 Vue 中的beforeEnter函数:...router.beforeEach(async(to, from, next) => { const toPath = to.path; const fromPath = from.path;})...react实现路由拦..原创 2020-08-04 09:42:11 · 13872 阅读 · 6 评论 -
解决react执行报错Module not found Cant resolve redux in node_modules
报错Module not found: Can't resolve 'redux' in 'F:\mylearn\react-auth\node_modules\react-redux\es\connect'如遇到这种错误:则可以试试安装下 npm install --save redux react-redux再执行就好了!原创 2022-05-01 11:43:18 · 4184 阅读 · 0 评论 -
react 灯箱组件 react-image-lightbox 的使用
记得要安装配套的react-modal 组件才行demo 点击这里https://download.youkuaiyun.com/download/lllomh/12092889原创 2020-01-13 10:47:28 · 2554 阅读 · 0 评论 -
react 幻灯组件 react-image-gallery 的使用
幻灯组件 demo 点这里https://download.youkuaiyun.com/download/lllomh/12099989import React,{Component} from 'react';import logo from './logo.svg';import './App.css';import ImageGallery from 'react-image-galle...原创 2020-01-13 16:11:30 · 2637 阅读 · 0 评论 -
React 中 路由 react-router-dom 的用法
理由定义:定义好 路由指向,然后再在index.js根文件中注册渲染在需要跳转的地方引入import { BrowserRouter as Router, Route,Link } from "react-router-dom"这样既可 实现了 路由跳转功能...原创 2021-05-01 06:55:37 · 1127 阅读 · 0 评论