vue 文本编辑器wangeditor版

<FormItem label="详情描述" label-position="top" prop="activityDescription">
            <br>
            <Editor ref="editor" @on-change="editorChange" v-if='!isSee' ></Editor>
            <p v-html="formData.activityDescription" v-if='isSee'></p>
            <p v-if='isSee && !formData.activityDescription'>暂无信息</p>
</FormItem>

import Editor from '@/components/wangeditor'

// 富文本改变时获取到文字
    editorChange(html, text) {
      const containsImage = this.$refs.editor.getEditor().search(/<img /i) >= 0
      if (containsImage) {
        this.$refs['formValidate'].fields.forEach(function(e) {
          if (e.prop === 'activityDescription') {
            e.resetField()
          }
        })
      }else{
        // this.$handleValidate('formValidate', this).then(valid => {
        //   if (valid) {
        //     this.handleSubmit()
        //   }
        // })
        var desp = this.$refs.editor.getEditor().replace(/<[^>]+>/g, '') // 去除所有的标签
        desp = desp.replace(/&nbsp;/ig, '')
        desp = desp.split('↵').join('')
        if(desp !== '' || desp !== undefined || desp.trim() !== '' || desp !== null || desp !== '<p><br></p>') {
          this.$refs['formValidate'].fields.forEach(function(e) {
            if (e.prop === 'activityDescription') {
              e.resetField()
            }
          })
        }else{
        }
      }
      this.formData.activityDescription = html
    },

详情获取赋值

if(this.$refs.editor) {
     this.$refs.editor.setHtml(info.goodsDescription)
}

重置清空

if(this.$refs.editor) {
   this.$refs.editor.setHtml('')
}

新增

Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组,数组中属性名的排列顺序和使用 for...in 循环遍历该对象时返回的顺序一致

Object.keys(this.formData).forEach((item, index) => {
        if (!params[item]) {
          if(this.formData[item]) {
            params[item] = ((this.formData[item] || null) + '').trim()
          }else{
            params[item] = null
          }
        }
      })

 

contentDescription: [
      {
        required: true,
        trigger: 'blur',
        validator: (rule, value, callback) => {
          const containsImage = _this.$refs.editor.getEditor().search(/<img /i) >= 0
          if (containsImage) {
            callback()
          }else{
            var desp = _this.$refs.editor.getEditor().replace(/<[^>]+>/g, '') // 去除所有的标签
            desp = desp.replace(/&nbsp;/ig, '')
            desp = desp.split('↵').join('')
            console.log(desp)
            if(desp.trim === '' || desp === undefined || desp.trim() === '' || desp === null || desp === '<p><br></p>') {
              callback(new Error('请输入详情描述'))
            }
          }
          callback()
        }
      }
    ]

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值