首页 VueJS Vue 3.0 使用富木HTML编辑器

Vue 3.0 使用富木HTML编辑器

作者:胡同里的砖头 围观群众:159 更新于:2024-02-06

1. 安装依赖包

npm install @wangeditor/editor-for-vue@next --save
2. 在引用页面加入如下代码
<template>

<el-button @click="gethtml">获取返回值</el-button>

<div style="border: 1px solid #ccc">
<Toolbar
style="border-bottom: 1px solid #ccc"
:editor="editorRef"
/>
<Editor
style="height: 300px; overflow-y: hidden;"
v-model="valueHtml"
@onCreated="handleCreated"
/>
</div>

<el-cascader
size="large"
:options="options"
v-model="selectedOptions"
@change="handleChange">
</el-cascader>
</template>

<script lang="ts" setup>
import { ref, reactive, onBeforeUnmount, shallowRef, onMounted } from "vue";
import '@wangeditor/editor/dist/css/style.css' // 引入 css
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
//富文本编辑器
// 编辑器实例,必须用 shallowRef
const editorRef = shallowRef()
const valueHtml = ref('<p>hellortrt778888</p>')
const handleCreated = (editor:any) => {
editorRef.value = editor // 记录 editor 实例,重要!
};

const gethtml = () => {
alert(valueHtml.value);
};

</script>
3.结果展示:

  • 本文标题: Vue 3.0 使用富木HTML编辑器
  • 文章分类:【VueJS】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8