Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue 富文本

作者:蓝梦月影   发布日期:2025-07-09   浏览:36

<template>
  <div>
    <quill-editor 
      v-model="content" 
      ref="myQuillEditor" 
      :options="editorOption" 
      @blur="onEditorBlur($event)" 
      @focus="onEditorFocus($event)"
      @ready="onEditorReady($event)">
    </quill-editor>
  </div>
</template>

<script>
import { quillEditor } from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

export default {
  components: {
    quillEditor
  },
  data() {
    return {
      content: '<p>富文本编辑器内容</p>',
      editorOption: {
        // 富文本编辑器配置项
        theme: 'snow',
        placeholder: '请输入内容...',
        modules: {
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'],
            ['blockquote', 'code-block'],
            [{ 'header': 1 }, { 'header': 2 }],
            [{ 'list': 'ordered' }, { 'list': 'bullet' }],
            [{ 'script': 'sub' }, { 'script': 'super' }],
            [{ 'indent': '-1' }, { 'indent': '+1' }],
            [{ 'direction': 'rtl' }],
            [{ 'size': ['small', false, 'large', 'huge'] }],
            [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
            [{ 'font': [] }],
            [{ 'color': [] }, { 'background': [] }],
            [{ 'align': [] }],
            ['clean']
          ]
        }
      }
    }
  },
  methods: {
    onEditorBlur(editor) {
      console.log('editor blur!', editor)
    },
    onEditorFocus(editor) {
      console.log('editor focus!', editor)
    },
    onEditorReady(editor) {
      console.log('editor ready!', editor)
    }
  }
}
</script>

<style scoped>
/* 自定义样式 */
.quill-editor {
  height: 300px;
}
</style>

解释说明:

  • quill-editor:这是 Vue 中使用的 Quill 编辑器组件,它允许用户创建和编辑富文本内容。
  • v-model="content":将编辑器的内容绑定到 content 数据属性上,这样可以双向绑定数据。
  • editorOption:这是一个对象,包含了 Quill 编辑器的各种配置选项。例如,theme 设置了编辑器的主题样式(如 snow),modules.toolbar 定义了工具栏中的按钮。
  • 事件处理@blur@focus@ready 是编辑器的事件监听器,当编辑器失去焦点、获得焦点或初始化完成时触发相应的回调函数。

这个示例展示了如何在 Vue 项目中集成一个功能丰富的富文本编辑器,并提供了基本的配置和事件处理。

上一篇:vue setup

下一篇:vue video

大家都在看

vue.config.js configu

node.js vue

vue 图表组件

vue3watch监听多个变量

vue查看版本

vue3 reactive对象重新赋值

vue等待几秒

vue3 setup computed

vue screenfull

vue json.stringify

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站