vue3使用quilleditor富文本框

参考官方文档:https://vueup.github.io/vue-quill/
1、先安装插件

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

npm install quill-image-uploader --save

2、局部引入

import { Quill, QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css'// 使用snow主题
import ImageUploader from 'quill-image-uploader';
Quill.register('modules/imageUploader', ImageUploader);

3、全部代码

<template>
    <QuillEditor
        ref="myQuillEditor"
        class="quill-editor"
        :style="{ height: height + 'px' }"
        contentType="html"
        v-model:content="innerContent"
        :options="options"
        @update:content="handleUpdate"
    >
    </QuillEditor>
</template>

<script setup>
/**
 * 官方文档: https://vueup.github.io/vue-quill/
 */
import { Quill, QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css'; //snow主题使用次样式
// import '@vueup/vue-quill/dist/vue-quill.bubble.css'; //bubble主题使用次样式
import ImageUploader from 'quill-image-uploader';
import { computed, getCurrentInstance, reactive } from 'vue';
import { customerUpload, DownloadBaseUrl } from '@/utils';

Quill.register('modules/imageUploader', ImageUploader);
const props = defineProps({
    height: {
        type: Number,
        default: 200
    },
    content: {
        type: String,
        default: ''
    },
    toolbar: {
        type: Array,
        default() {
            return [
                ['bold', 'italic', 'underline', 'strike'], // toggled buttons
                ['blockquote', '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' }],
                [{ size: ['small', false, 'large', 'huge'] }], // text direction // custom dropdown
                [{ header: [1, 2, 3, 4, 5, 6, false] }],
                [{ color: [] }, { background: [] }], // dropdown with defaults from theme
                [{ font: [] }],
                [{ align: [] }],
                ['link', 'video', 'image'],
                ['clean'] // remove formatting button
            ];
        }
    }
});
const emit = defineEmits(['update:content']);
const innerContent = computed({
    get() {
        return props.content;
    },
    set(value) {
        emit('update:content', value);
    }
});

const { proxy } = getCurrentInstance();
const options = reactive({
    modules: {
        toolbar: props.toolbar,
        imageUploader: {
            upload: (file) => {
                return new Promise((resolve, reject) => {
                    customerUpload(file)
                        .then((res) => {
                            console.log('res:', res);
                            resolve(`${DownloadBaseUrl}pk=${res.data[0].pk}`);
                        })
                        .catch((err) => {
                            proxy.$message.error(err);
                            reject(err);
                        });
                });
            }
        }
    },
    placeholder: '请输入内容',
    readOnly: false,
    theme: 'snow'
});
const handleUpdate = (content) => {
    console.log(content, innerContent.value);
};
</script>

<style></style>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3中使用vue-quill-editor,你可以按照以下步骤进行配置: 1. 首先,你需要安装vue-quill-editor插件。你可以通过运行以下命令来安装插件: ``` npm install @vueup/vue-quill@alpha --save ``` 2. 在你的Vue项目的入口文件(通常是main.js)中,导入所需的组件和样式。你可以按照以下方式导入: ```javascript import { createApp } from 'vue' import { QuillEditor } from '@vueup/vue-quill' import '@vueup/vue-quill/dist/vue-quill.snow.css'; const app = createApp() app.component('QuillEditor', QuillEditor) ``` 3. 现在,你可以在你的Vue组件中使用vue-quill-editor了。你可以按照官方文档提供的用法进行使用。你可以参考官方文档的地址:\[https://vueup.github.io/vue-quill/guide/usage.html#in-single-file-component\](https://vueup.github.io/vue-quill/guide/usage.html#in-single-file-component)。 希望这些信息对你有帮助! #### 引用[.reference_title] - *1* *2* [Vue3使用文本编辑器QuillEditor](https://blog.csdn.net/xaishujin/article/details/115552198)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [vue3使用quill文本编辑器,保姆级教程,文本踩坑解决](https://blog.csdn.net/moanuan/article/details/128240291)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值