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

vue 富文本插件

作者:风中孤狼   发布日期:2026-07-06   浏览:51

<template>
  <div>
    <quill-editor 
      v-model="content" 
      :options="editorOptions"
      @blur="onEditorBlur" 
      @focus="onEditorFocus" 
      @ready="onEditorReady"
    />
  </div>
</template>

<script>
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css'

export default {
  components: {
    QuillEditor
  },
  data() {
    return {
      content: '',
      editorOptions: {
        theme: 'snow',
        modules: {
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'],
            [{ '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] }],
            [{ 'color': [] }, { 'background': [] }],
            [{ 'font': [] }],
            [{ 'align': [] }],
            ['clean']
          ]
        }
      }
    }
  },
  methods: {
    onEditorBlur(editor) {
      console.log('editor is blurred', editor)
    },
    onEditorFocus(editor) {
      console.log('editor is focused', editor)
    },
    onEditorReady(editor) {
      console.log('editor is ready', editor)
    }
  }
}
</script>

<style scoped>
/* 可以根据需要添加样式 */
</style>

解释说明

  1. 模板部分 (<template>):

    • 使用 quill-editor 组件,绑定 v-modelcontent 数据属性。
    • :options 绑定编辑器的配置选项。
    • 监听 @blur, @focus, 和 @ready 事件,分别调用对应的方法。
  2. 脚本部分 (<script>):

    • 引入 QuillEditor 组件和对应的样式文件。
    • components 中注册 QuillEditor 组件。
    • 定义 data 方法返回初始数据:
      • content: 富文本内容。
      • editorOptions: 编辑器的配置选项,包括主题和工具栏按钮。
    • 定义 methods 方法处理编辑器的不同事件(模糊、聚焦、准备就绪)。
  3. 样式部分 (<style scoped>):

    • 可以根据需要添加自定义样式,这里留空以便灵活扩展。

上一篇:vue响应式

下一篇:nginx部署多个vue项目

大家都在看

vue.js devtools用法

three.js vue

vue js for循环

vue.min.js 本地引入

vue.js 3

highlight.js vue

vue.config.js 配置

vue.config.js 配置代理

vue.config.js devserv

vue.config.js configu

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

Laravel 中文站