在nuxt中引入wangeditor5报错解决

我这里使用的是nuxt3+vue3,wangeditor5

不需要再nutx.config.js中额外配置什么,直接按照以下步骤就可以实现

一、使用npm下载wangeditor/editor wangeditor/editor-for-vue

二、直接编写组件,在commponents里面创建

<template>

    <div ref="editorContainer" class="editor-container" ></div>

</template>

<script setup>

import "@wangeditor/editor/dist/css/style.css";  //引入样式

import { ref, onMounted, onBeforeUnmount } from "vue";

import { createEditor, createToolbar } from "@wangeditor/editor"; //引入创建element的包

const editorContainer = ref(null);

let editor = null;

onMounted(() => {

    editor = createEditor({

        selector: editorContainer.value,

        config: {

            placeholder: "请输入内容...",

            autoFocus: true,

            showLinkImg: false,

            allowImageRemote: false

        },

        mode: "default" // 或者 'simple' 简单模式

    });

    createToolbar({

        editor,

        selector: editorContainer.value,

        config: {

            showLinkImg: false,

            allowImageRemote: false

        }

    });

    setTimeout(() => {

        editor.focus();

    }, 1000);

});

onBeforeUnmount(() => {

    if (editor) {

        editor.destroy();

    }

});

</script>

<style scoped>

.editor-container {

    border: 1px solid #ccc;

    padding: 10px;

    min-height: 300px;

}

:deep .w-e-bar-item:nth-child(17),

:deep .w-e-bar-item:nth-child(22),

:deep .w-e-bar-item:nth-child(23),

:deep .w-e-bar-item:nth-child(24),

:deep .w-e-bar-item:nth-child(25),

:deep .w-e-bar-item:nth-child(26) {

    display: none;

}

.editor-container {

    border: 1px solid #ccc;

    padding: 10px;

    min-height: 300px;

    position: relative; /* 确保相对定位 */

    z-index: 1; /* 确保编辑器位于前端 */

}

</style>

三、在文件中引入就大功告成了

注意:务必在组件外面包裹client-only标签。不然会报错

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值