[vue3] 富文本

 ✨✨个人主页:沫洺的主页

📚📚系列专栏: 📖 JavaWeb专栏📖 JavaSE专栏 📖 Java基础专栏📖vue3专栏 

                           📖MyBatis专栏📖Spring专栏📖SpringMVC专栏📖SpringBoot专栏

                           📖Docker专栏📖Reids专栏📖MQ专栏📖SpringCloud专栏     

💖💖如果文章对你有所帮助请留下三连✨✨

🛴富文本

🛵纯文本就是用文本编辑器编写,输入什么就是什么的文档。

🛵富文本是通过富文本编辑器进行渲染和计算,然后再呈现给你看的文档,所见即所得。

🛵doc,docx,rtf,pdf都是富文本的格式, 包括浏览器等都可算作广义上的富文档软件

🛵富文本地址:wangEditor

🚲安装

🛵安装依赖包

🛵npm install @wangeditor/editor-for-vue@next --save

 🚲新建src/views/Editor.vue

🛵创建后添加路由

🛵App.vue

<template>
 <router-link to="/home">首页</router-link><br />
  <router-link to="/poduct/list">商品列表</router-link><br />
  <router-link to="/editor">富文本</router-link><br />
  <hr />
  <router-view></router-view>
</template>
<script setup lang="ts">

</script>

🛵router/index.ts

import { createRouter, createWebHistory } from "vue-router";
const routes = [
    {
        path: '/home',
        component: () => import("@/views/Home.vue")
    },
    {
        path: '/poduct',
        component: () => import("@/views/poduct/Index.vue"),
        children: [
            {
                path: '/poduct/list',
                component: () => import("@/views/poduct/List.vue"),
            }
        ]
    },
    {
        path: '/editor',
        component: () => import("@/views/Editor.vue")
    },
]
const router = createRouter({
    history: createWebHistory(),
    routes
})
export default router

🚲编辑Editor.vue

<template>
    <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>
</template>
<script setup lang="ts">
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>hello 富文本编辑器</p>')
const handleCreated = (editor: any) => {
    editorRef.value = editor // 记录 editor 实例,重要!
}
</script>

 🚲效果图

 🚲获取富文本内容

加个按钮

<el-button type="primary" @click="getEditor">获取富文本内容</el-button>

定义getEditor方法

const getEditor  = ()=>{

    console.log(valueHtml.value);

}

 🚲效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

沫洺

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

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

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

打赏作者

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

抵扣说明:

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

余额充值