
react
banzhuanren1
这个作者很懒,什么都没留下…
展开
-
hooks子组件修改父组件值
刚刚学习hooks ,写个dome记录一下,亲测可用父组件import React , { useState ,createContext ,useContext} from 'react';import Zi from './zi'// 创建上下文export const NumContext = createContext();function Fu (){ const ...原创 2019-11-12 17:50:22 · 7881 阅读 · 3 评论 -
Support for the experimental syntax 'decorators-legacy' isn't currently
刚接触mobx,给我报个错,Support for the experimental syntax ‘decorators-legacy’ isn’t currently ,竟然不支持这个语法,后来查了资料解决了问题第一步:npm install @babel/plugin-proposal-decoratorsnpm install @babel/plugin-proposal-class...原创 2019-11-05 15:53:54 · 867 阅读 · 0 评论 -
react-redux基本使用
Redux 的 React 绑定库是基于 容器组件和展示组件相分离 的开发思想接触这个不就,如果错误欢迎大家指正actionType.js随着项目大型化,所以要抽取出来一个actionType.js文件来记录各种actionType常量export const SET_CURRENTINDEX ='SET_CURRENTINDEX';store.jsimport { createS...原创 2019-10-31 11:37:11 · 150 阅读 · 0 评论 -
redux监控数据变化
组件.js constructor(props) { super(props); this.state = { songList:[], 通过subscribe可以监控数据变化,并返回unsubscribe unsubscribe:store.subscribe(() => ...原创 2019-10-28 09:55:43 · 2018 阅读 · 0 评论 -
redux基本使用
actionType.jsexport const SET_CURRENTINDEX ='SET_CURRENTINDEX';store.jsimport { createStore } from 'redux';import rootReducer from '../reducers';const store = createStore(rootReducer,window.__R...原创 2019-10-28 09:42:36 · 192 阅读 · 1 评论 -
react 子组件onClick 方法自动执行问题
在页面渲染 的时候发现子组件的onClick方法自动执行了,代码如下//父组件 selectItem(index){ console.log('点击歌曲'); console.log(index) } render(){ return( <> { ...原创 2019-10-17 16:29:23 · 2336 阅读 · 1 评论 -
Cannot read property ‘push’ of undefined
在使用 this.props.history.push(’/singer/’+item.id)进行跳转的时候报错:Cannot read property ‘push’ of undefined,因为之前都是这么跳转的没有报错,这次竟然报错了,很郁闷。最简单直接在父组件加上history={ this.props.history }例如: <SingerView singerList=...原创 2019-10-14 16:13:41 · 11045 阅读 · 0 评论 -
Can't perform a React state update on an unmounted component.
再在搜索框需求的是出现了这个错误,当搜索框内容全部删除的时候报错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...原创 2019-10-12 17:46:19 · 388 阅读 · 0 评论 -
react父子组件传值
子组件向父组件传值子组件import React , { Component } from 'react';import { Input } from 'antd';import './SearchBox.less';class SearchBox extends Component{ constructor(props){ super(props); }...原创 2019-10-12 12:12:43 · 198 阅读 · 0 评论 -
react 将字符串转成html
在写项目的过程中,经常遇到渲染的数据是数组内嵌套数组的,之前都是用父子组件传值的方式来解决,今天发现项目中特别多这样的需求,如果都用子组件的话,就需要创建很多子组件,工作量也增加了很多。所以就想到了将html字符串转换成html;该方法只适合纯静态展示,如果需要逻辑操作,建议还是使用父子组件传值的方式方法如下:import React , { Component } from 'react'...原创 2019-10-11 16:17:02 · 3192 阅读 · 1 评论 -
react 报错 using incorrect casing.
写练习的时候引入子组件,但是渲染的时候报错:using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.仔细看了下发现是组件的首字母小写引起的,看来写代码的时候还是粗心了,记录下代码简陋,主要说问题 哈哈 render(){ return( ...原创 2019-10-11 15:15:54 · 1643 阅读 · 0 评论 -
react使用jsonp跨域
接上一篇,因为使用proxy 方法请求QQ音乐返回的是jsonp格式的数据,想使用的话还要进行截取,所以干脆就直接使用jsonp来进行跨域了,数据可以直接使用也省的在麻烦了。上代码目录结构src/common/jsonp.jsimport originJsonp from 'jsonp'export default function jsonp(url,data,option){ ur...原创 2019-10-09 16:33:07 · 3145 阅读 · 0 评论 -
react项目中跨域问题
做一个练习遇到了跨域问题,网上找了很多方法顺带问各位大神一个问题:我的方法三解决方案中,代理路径的参数怎么抽取出来,我想在axios.get请求的时候动态发送过去,求大神支支招方法一:在package.json中添加以下代码 ----------- 试过无效//package.json中加入 "proxy": { "/api/RoomApi": { "t...原创 2019-10-09 14:23:40 · 3183 阅读 · 0 评论 -
antd table表格组件基本使用
第一次使用antd的table表格组件,借用官方文档数据,展示下Demoimport React from 'react';import { Table } from 'antd';const columns = [ { title: 'Name', dataIndex: 'name', render: text => <a>{...原创 2019-10-08 16:51:22 · 10914 阅读 · 0 评论 -
react+antd配置less和按需加载
第一次写react相关东西,如有错误,请大佬指点想用react+antd做个练习,发现antd是用less的方式开发的,但是初始化的脚手架是没有config这个文件的,想改配置去无从下手,在网上查了下资料,好几个是在webpack.config.dev.js中进行配置的,但是我下载的版本是最新的,在config文件夹下没有这个webpack.config.dev.js文件,最后找了资料发现了方法...原创 2019-09-19 17:40:28 · 1668 阅读 · 0 评论