vue3 获取vue-quill3编辑器实例,使用api

顺便写一下vue3中quill的使用方法
点击前往quill官网
安装我就不写了 官网里有 npm 一下
在这里插入图片描述
在这里插入图片描述
注册完就可以组件里使用了
在这里插入图片描述
其他属性参考官方文档就可以,我来展示一下options,我是用模块导入的

export default {
    debug: "info",
    modules: {
      toolbar: [
        "bold",
        "italic",
        "underline",
        "strike", // toggled buttons
        "blockquote",
        "image",
        // "code-block",

        { header: 1 },
        { header: 2 }, // custom button values
        { list: "ordered" },
        { list: "bullet" },
        // { script: "sub" },
        // { script: "super" }, // superscript/subscript
        { indent: "-1" },
        { indent: "+1" }, // outdent/indent
        { direction: "rtl" }, // text direction

        { size: ["small", false, "large", "huge"] }, // custom dropdown
        { header: [1, 2, 3, 4, 5, 6, false] },

        { color: [] },
        { background: [] }, // dropdown with defaults from theme
        { font: [] },
        { align: [] },
        "clean", // remove formatting button
      ],
    },
    placeholder: "编辑您的内容...",
    theme: "snow",
}

效果展示:
在这里插入图片描述
界面简洁大方,二次开发很方便,支持作者

下面是使用实例
通过ref

const quillEditor=ref();
quillEditor.value.setText("")//设置文本为空

很清爽,很方便,很棒

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
Vue 3 中使用 Vue-Quill-Editor 可能会出现以下错误: ``` [vue-composition-api] "Uncaught TypeError: Cannot read property '_vm' of undefined" ``` 这是因为 Vue 3 中使用了 Composition API,而 Vue-Quill-Editor 还没有完全适配 Composition API。解决该问题可通过在 `setup()` 函数中引入 `onMounted`、`onUnmounted` 等钩子函数,然后手动初始化 Quill 编辑器。 以下是一个示例: ```vue <template> <div> <div ref="editor"></div> </div> </template> <script> import { onMounted, onUnmounted, ref } from 'vue'; import Quill from 'quill'; import 'quill/dist/quill.snow.css'; export default { setup() { const editor = ref(null); onMounted(() => { const quill = new Quill(editor.value, { modules: { toolbar: [ ['bold', 'italic', 'underline', 'strike'], [{ list: 'ordered' }, { list: 'bullet' }], ['link', 'image'], ], }, theme: 'snow', }); quill.on('text-change', () => { console.log(quill.root.innerHTML); }); // save the instance of Quill editor editor.value.__quill = quill; }); onUnmounted(() => { // destroy the instance of Quill editor editor.value.__quill.destroy(); editor.value.__quill = null; }); return { editor, }; }, }; </script> ``` 在上述示例中,我们在 `setup()` 函数中使用 `onMounted` 和 `onUnmounted` 钩子函数来初始化和销毁 Quill 编辑器。同时,我们在 `onMounted` 中监听 `text-change` 事件,以便在编辑器内容发生变化时执行一些操作。最后,我们将 Quill 实例保存在 `editor.value.__quill` 中,以便在其他地方访问该实例

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Min;

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

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

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

打赏作者

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

抵扣说明:

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

余额充值