一般UEditor用于表单的新建和编辑

<FormItem {...formItemLayout} label='商品详情'>
  {getFieldDecorator('detail', {
    rules: [{ required: true, message: '请输入商品详情' }]
  })(<Ueditor width={692} id="detail" toolbars={videoToolbar} />)}
</FormItem>

id和name要相同

表单提交的时候校验详情是否输入 (因为form.getFieldValue('detail')拿到的值是‘contentChange’,不能作为是否为空的凭证)

if (!getContent('detail')) {
  form.setFields({
  detail: {
  value: getContent('detail'),
errors: [new Error(`请输入${type == 1 ? '音频' : '视频'}详情`)]
}
})
}

编辑的时候,需要将内容写入UEditor

edit:是否是编辑页 如果是新建页就不用写入

hasDetail:是否已经渲染好了detail  componentWillReceiveProps会执行好几次 如果不判断是否已经渲染好了detail editor.ready会进入死循环

courseDetail.detail:渲染的数据

componentDidMount和componentWillReceiveProps都要执行相同的步骤  因为在实践过程中发现有少数情况 在进入编辑页或者刷新编辑页时editor不能被成功渲染

componentDidMount() {
const { courseDetail, edit, hasDetail, dispatch } = this.props
if (courseDetail.detail && edit && !hasDetail) {
const editor = getUeditor('detail')
editor.ready(function() {
dispatch({
type: 'courseManagement/saveHasDetail',
payload: true
})
editor.setContent(courseDetail.detail)
})
}
}
componentWillReceiveProps(nextProps) {
const { courseDetail, edit, hasDetail, dispatch } = nextProps
if (courseDetail.detail && edit && !hasDetail) {
const editor = getUeditor('detail')
editor.ready(function() {
dispatch({
type: 'courseManagement/saveHasDetail',
payload: true
})
editor.setContent(courseDetail.detail)
})
}
}

React中使用UEditor的更多相关文章

  1. 理解React中es6方法创建组件的this

    首发于:https://mingjiezhang.github.io/(转载请说明此出处). 在JavaScript中,this对象是运行时基于函数的执行环境(也就是上下文)绑定的. 从react中的 ...

  2. 【原】React中,map出来的元素添加事件无法使用

    在使用react中,经常用到react的map函数,用法和jquery里中的map一样,但是,如果你在每个map出来的元素中添加,你会发觉添加的事件无法关联, 比如,我们很多的评论,我需要在每个评论下 ...

  3. React中props.children和React.Children的区别

    在React中,当涉及组件嵌套,在父组件中使用props.children把所有子组件显示出来.如下: function ParentComponent(props){ return ( <di ...

  4. asp.net中使用ueditor

    原文地址:http://blog.uoolo.com/Article/16 还有在MVC中使用ueditor:http://blog.uoolo.com/Article/111 最初百度了一下“编辑器 ...

  5. Immutable 详解及 React 中实践

    本文转自:https://github.com/camsong/blog/issues/3 Shared mutable state is the root of all evil(共享的可变状态是万 ...

  6. React中父组件与子组件之间的数据传递和标准化的思考

    React中父组件与子组件之间的数据传递的的实现大家都可以轻易做到,但对比很多人的实现方法,总是会有或多或少的差异.在一个团队中,这种实现的差异体现了每个人各自的理解的不同,但是反过来思考,一个团队用 ...

  7. React中使用CSSTransitionGroup插件实现轮播图

    动画效果,是一个页面上必不可少的功能,学习一个新的东西,当然就要学习,如何用新的东西,用它的方法去实现以前的东西啦.今天呢,我就在这里介绍一个试用react-addons-css-transition ...

  8. 在React中使用Redux

    这是Webpack+React系列配置过程记录的第六篇.其他内容请参考: 第一篇:使用webpack.babel.react.antdesign配置单页面应用开发环境 第二篇:使用react-rout ...

  9. React中的路由系统

    React中的路由系统 提起路由,首先想到的就是 ASPNET MVC 里面的路由系统--通过事先定义一组路由规则,程序运行时就能自动根据我们输入的URL来返回相对应的页面.前端中的路由与之类似,前端 ...

随机推荐

  1. .NET截取指定长度字符超出部分以"..."代替

    /// <summary> /// 将指定字符串按指定长度进行剪切, /// </summary> /// <param name= "Str "&g ...

  2. CentOS7.4使用yum安装MySQL5.6

    CentOS默认数据库为mariadb可以使用yum安装MySQL5.6 系统版本查看 下载yum源安装 wget http://dev.mysql.com/get/mysql-community-r ...

  3. 理论实践:循序渐进理解AWR细致入微分析性能报告

    1. AWR 概述 Automatic Workload Repository(AWR) 是10g引入的一个重要组件.在里面存贮着近期一段时间内(默认是7天)数据库活动状态的详细信息. AWR 报告是 ...

  4. Constructor Overloading in Java with examples 构造方法重载 Default constructor 默认构造器 缺省构造器 创建对象 类实例化

    Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Cl ...

  5. "errmsg" : "distinct too big, 16mb cap",

    repl_test:PRIMARY> show dbs admin 0.000GB direct_vote_resource 16.487GB local 14.860GB personas 3 ...

  6. git-【七】bug分支

    在开发中,会经常碰到bug问题,那么有了bug就需要修复,在Git中,分支是很强大的,每个bug都可以通过一个临时分支来修复,修复完成后,合并分支,然后将临时的分支删除掉. 比如我在开发中接到一个40 ...

  7. oracle 安装,登陆,配置

    1:查看: https://blog.csdn.net/u014177640/article/details/71023380/ 2:登陆  https://zhidao.baidu.com/ques ...

  8. 使用Vue-cli搭建项目与目录详解

    1.介绍 vue-cli这个构建工具大大降低了webpack的使用难度,支持热重载,有webpack-dev-server的支持,相当于启动了一个请求服务器,给你搭建了一个测试环境,只关注开发就OK. ...

  9. Websocket、长连接、循环连接

    [转]转自知乎高票回答  https://www.zhihu.com/question/20215561 一.WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系 ...

  10. Core Java 6

    p277~p279: 1.使用解耦合的 try/catch 和 try/finally 语句块可以提高代码的清晰度,并且会报告 finally 子句中出现的错误. 2.假设利用 return 语句从 ...