React cannot set property props of undefined
在react开发的时候,调用this.props时候,提示说没props (undefined)
如图,在函数中调用props,
调试的时候,网页提示 “cannot read property ‘props’ of undefined”
出现问题的原因是 在调用触发函数的时候,没有对函数进行绑定,这个函数本身用的是其本身的this ,不是全局this。
解决方案就是对函数进行绑定。
绑定方式一:在触发函数上进行绑定
绑定方式二: 在构造中进行绑定
PS:
并不是所有的函数都需要绑定,一般由组件自带的触发函数就可以不用绑定。自己定义的函数需要进行绑定。
React cannot set property props of undefined相关推荐
- 解决React中路由跳转报错:Cannot read property ‘push’ of undefined
React中路由跳转报错: 页面在Router中配置了,但组件无法使用 this.props.history.push() 进行跳转,并且会出现报错:Cannot read property 'pus ...
- create-react-app创建的项目配置多入口MPA模式。报Cannot read property ‘filter’ of undefined
create-react-app创建的项目配置多入口MPA模式.报Cannot read property 'filter' of undefined 多入口配置 一.首先eject项目 执行npx ...
- Cannot read property ‘type‘ of undefined Occurred while linting **\index.jsx:1
今一个react 中使用mobx 老是提示Cannot read property 'type' of undefined Occurred while linting **\index.jsx:1 ...
- chrome浏览器不能录音:Uncaught TypeError: Cannot read property ‘getUserMedia‘ of undefined解决方法
Uncaught TypeError: Cannot read property 'getUserMedia' of undefined解决方法 javascript 打不开浏览器录音功能的问题解决方 ...
- 使用JQuery Validate插件的报Cannot read property 'settings' of undefined错误的解决方法
一.问题描述: 因为最近在做动态表单,很多字段需要动态添加验证,而我在动态添加删除校验规则时,浏览器经常报Cannot read property 'settings' of undefined,每次 ...
- jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' of undefined
Jquery DataTable使用报这个错: jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' o ...
- VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法...
data里面做了定义 在方法里面进行赋值 用 this.info = repos.data 数据可以请求到,但是会报错 TypeError: Cannot set property 'listgrou ...
- 记一次前端问题解决历程(Cannot read Property ‘call‘ of undefined)
记一次前端问题解决历程(Cannot read Property 'call' of undefined) 参考文章: (1)记一次前端问题解决历程(Cannot read Property 'cal ...
- vue 报错 Cannot read property ‘__ob__‘ of undefined的解决方法
vue 报错 Cannot read property '__ob__' of undefined的解决方法 参考文章: (1)vue 报错 Cannot read property '__ob__' ...
最新文章
- 深度学习之输入通道个数、卷积核通道个数,卷积核个数、输出通道个数的关系
- Bootstrap按钮使用
- python 为何要学16进制,从十六进制Python中的补
- python定时发送邮件
- 2/2 常用函数:标准库函数
- OpenStack Telemetry系统架构及实践
- freemarker常见语法大全
- ejb+jpa_使用Arquillian(包括JPA,EJB,Bean验证和CDI)测试Java EE 6
- linux下查看中断请求记录 IRQ
- python matpltlib实践——画直方图、折线图
- 思科C9500交换机介绍及光模块解决方案
- python实现热力图_基于 Folium 的 Python 热力图实现
- 兑吧开发规范《源Java手册》
- 以莺尾花数据集为例,探讨R模型部署之道
- C++ 基础知识throw的用法
- 第四章 web前端开发工程师--JavaScript京东商城项目开发 4-2 京东商城导航栏
- php 说说,PHP利用Qzone的说说接口发表说说开发日记
- 不思议迷宫量子计算机,不思议迷宫男巫刷法及男巫的猫形态详解
- 【转载】程序员毕业后的第二年发生了哪些变化?
- Apple开发者账号介绍及证书配置说明。