vue+element-ui 使用富文本编辑器

9 篇文章 0 订阅

vue+element-ui 使用富文本编辑器

  1. npm安装编辑器组件
    npm install vue-quill-editor –save
  2. 在项目中引入quill-config.js文件(网上可以找到)
    在这里插入图片描述
  3. 在需要使用的页面引入(代码如下)
<template>
  <section>
    <el-form
      ref="forms"
      :model="form"
      :rules="rules"
      label-width="120px"
      @submit.prevent="onSubmit"
      style="margin:20px;margin-left:150px;width:60%;min-width:600px;"
    >
      <el-row>
        <el-col :span="10">
          <el-form-item label="富文本:" prop="content" style="margin-bottom:70px">
            <quill-editor
              class="ql-editor"
              ref="myTextEditor"
              style="width:800px;"
              :options="quillOption"
              v-model="form.content"
            ></quill-editor>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item class="subBtn">
        <elbutton type="primary" @click="subBtnFn('forms')">保存</el-button>
        <el-button @click="cancleFn">取消</el-button>
      </el-form-item>
    </el-form>
  </section>
</template>

<script>
import { Quill, quillEditor } from 'vue-quill-editor'
import quillConfig from '../../components/common/quill-config'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

export default {
  components: {
    quillEditor
  },
	data() {
		return {
      form: {
        content: '', // 富文本
      },
      rules: {
        content: [{ required: true, message: '请编辑文本', trigger: 'blur' }]
      },
      editor: null, // 富文本编辑器对象
      editorOption: { //  富文本编辑器配置
        placeholder: '请输入',
        theme: 'snow', // or 'bubble'
        modules: {
          toolbar: {
            container: '#toolbar'
          }
        }
      },
      content: '<h2>hello quill-editor</h2>',
      quillOption: quillConfig
    }
  },
  mounted () {
  },
  methods: {
  }
}
</script>

<style type="text/scss" lang="scss" scoped>
.nameInp {
  width: 284px;
}
.nameInps {
  width: 80%;
}
.subBtn {
  display: inline-block;
  margin-left: 26%;
  .el-button {
    width: 110px;
    margin-top: 10px;
  }
}
</style>

以上就是简单的在vue+element-ui 使用富文本编辑器,效果图如下:
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值