- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的项目中使用 PrimeReact 的编辑器组件
import React from 'react';
import Editor from './editor/Editor';
const header = (
<span className="ql-formats">
<button className="ql-bold" aria-label="Bold"></button>
<button className="ql-italic" aria-label="Italic"></button>
<button className="ql-underline" aria-label="Underline"></button>
</span>
);
function Admin() {
return(
<div className="Admin">
<header className="App-header">
<Editor style={{height:'320px'}} value={this.state.text.bind(this)} onTextChange={(e) => this.setState({text: e.htmlValue}).bind(this)} />
</header>
</div>
);
}
但是当我运行此代码时,出现以下错误
TypeError: this is undefined
最佳答案
您使用函数组件而不是类组件请阅读Function component vs class component
Function component vs class component 2
对于快捷方式解决方案,请使用 useState
import React, {useState} from 'react'; //import useState
import Editor from './editor/Editor';
const header = (
<span className="ql-formats">
<button className="ql-bold" aria-label="Bold"></button>
<button className="ql-italic" aria-label="Italic"></button>
<button className="ql-underline" aria-label="Underline"></button>
</span>
);
function Admin() {
const [text,setText] = useState('')
return(
<div className="Admin">
<header className="App-header">
<Editor style={{height:'320px'}} value={text} onTextChange={(e) => setText({text: e.htmlValue}).bind(this)} />
</header>
</div>
);
}
关于javascript - TypeError 这是未定义的原因,使用 primereact,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59783688/
我似乎无法使用 styled-component 来设置 PrimeReact 组件的样式。 鉴于下面的代码呈现一个 InputText,我的意图是改变它的宽度。但它不起作用。 import styl
我是 Node、JavaScript 和 React 的新手。我必须在下拉列表中显示数据列表,然后将选定的数据保存在数据库中。问题是如何显示要选择的数据列表 他们以这种方式获取数据
我希望能够在 primereact 的主题之间切换,而不是导入一个主题,然后它会影响我的整个应用程序,而且我没有在暗模式或亮模式之间切换的选项。 最佳答案 在网站上观察他们是怎么做的www.prime
我正在使用 prime react 数据表 显示数据表,当鼠标悬停在单元格上时,我想显示工具提示或标题,如下图所示。 我检查了 Column 组件,但没有找到任何相关关键字来显示单元格上的工具提示或标
我想使用 Primereact 框架开发一个 React Js 应用程序。现在我遇到了一些导入无法找到的问题。 Import import {Button} from 'primereact/Butt
我想知道是否可以在 PrimeReact 中使用 react-icons 包中的图标,因为不幸的是 primeIcons 包不包含我的项目所需的所有图标。 我还没有找到解决方案,因为 react-ic
我是 React/Spring 初学者,我不知道如何使用 Primereact 制作文件上传。 他们的文档说明如下( https://www.primefaces.org/primereact/#/f
我正在尝试在我的项目中使用 PrimeReact 的编辑器组件 import React from 'react'; import Editor from './editor/Editor'; con
我试图将焦点集中在 primereact 的“Dropdown”组件上,但焦点并未集中在“Dropdown”组件上。 我已经使用了 https://www.primefaces.org/primere
我收到以下错误- Failed to compile ./node_modules/primereact/components/dropdown/DropdownPanel.js Module not
我启用了 CSS modules within webpack.config在我的 React 应用程序中,这样我就可以在本地将 CSS 文件范围限定到各个组件。我也在尝试使用 PrimeReact
我是一名优秀的程序员,十分优秀!