zoukankan      html  css  js  c++  java
  • React中使用UEditor

    一般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)
          })
        }
      }
  • 相关阅读:
    Linux中gdb 查看core堆栈信息
    爱因斯坦名言
    Symbian OS 源码下载方式
    Windows 2003+VS2005+SP1 “无法使用此产品的安装源,请确认安装源存在,并且您可以访问它”的错误
    Visual Studio 2012 Ultimate RTM 序列号
    STL容器erase的使用陷阱
    C++ 迭代器失效
    C++ 类的静态成员详细讲解[静态成员变量链接错误]
    Ubuntu 启动黑屏解决
    android中KSOAP2中的anytype{}问题
  • 原文地址:https://www.cnblogs.com/AnnieShen/p/9034731.html
Copyright © 2011-2022 走看看