vue3 富文本quill

文章介绍了如何在Vue项目中安装并使用vue-quill组件,包括配置选项、子组件引入方法,以及如何通过定时器实现内容变化的延迟处理,以避免频繁操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装

npm install @vueup/vue-quill@latest --save

子组件引入使用

<template>
    <QuillEditor ref="QuillEditorRef" :options="options" :content="textarea" content-type="html"
        @update:content="textChange" />
</template>
<script setup>
import {
    QuillEditor
} from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css';
import { getCurrentInstance, onMounted, onUnmounted, ref, defineEmits } from "vue";
const options = ref({

    debug: 'info',
    modules: {
        // toolbar: ['bold', 'italic', 'underline'],
    },
    placeholder: '请输入需要的内容',
    readOnly: false,
    theme: 'snow',
}
)
const Emits = defineEmits()
const textarea = ref()
const timer = ref()
const textChange = (e) => {
    if (timer.value) {
        clearTimeout(timer.value)
    } // 每次进来的时候都将之前的清除掉,如果还没到 600毫秒(600毫秒自定义) 的时候就将之前的清除掉,这样就不会触发之前setTimeout绑定的事件, 如果超过 600豪秒,之前的事件就会被触发下次进来的时候同样清除之前的timer
    timer.value = setTimeout(() => { //箭头函数 注意this
        // 在这里进行我们的操作  这样就不会频繁的进行我们这里面的操作了
        var value = e;
        var detail = {
            "value": value
        };
        var options = {};
        textarea.value = e
        // console.log(e, '参数98', textarea.value);
        Emits("changeEmits", textarea.value)
    }, 600)

}

</script>

父组件引用子组件

<template>
  <div class="home">
    <QuillEditor @change="(html) => { html为更新值 }" 
  		:html="默认值" @changeEmits="changeEmits"></QuillEditor>
  </div>
</template>

<script setup>
import { getCurrentInstance, onMounted, onUnmounted, ref } from "vue";
import QuillEditor from "../../components/QuillEditor/QuillEditor.vue"
const changeEmits= (e)=>{
  console.log("changeEmits",e)
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呱嗨喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值