当前位置: 首页 > news >正文

vue中使用富文本编辑器

vue中使用富文本编辑器(wangEditor)

wangEditor官网地址:https://www.wangeditor.com/

使用示例

<template><div class="app-container"><div class="box"><div class="editor-tool"><Toolbarstyle="border-bottom: 1px solid #ccc":editor="editorRef":defaultConfig="toolbarConfig"mode="default"/><Editorstyle="height: 300px; overflow-y: hidden;"v-model="valueHtml":defaultConfig="editorConfig"mode="default"@onCreated="handleCreated"/></div><div class="btn"><el-button type="primary" @click="isOpen = true">编辑器内容</el-button></div><Demo v-model:myValue="isOpen"  v-model:content="valueHtml"/></div></div>
</template><script lang="ts" setup>
import { onBeforeUnmount, ref, shallowRef} from 'vue'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { uploadImage } from "@/api/cabinet/index.js";
import { getToken } from '@/utils/auth'
import Demo from '@/components/Demo.vue'
import '@wangeditor/editor/dist/css/style.css' // 引入 css
const editorRef = shallowRef()
const valueHtml = ref(null) //富文本里面内容,传给后端
const toolbarConfig = {} //工具栏配置
const editorConfig = { //内容区域配置placeholder: '请输入内容',MENU_CONF: {}
}
const isOpen = ref(false) //弹窗是否打开
const url = 'http://192.168.31.74:9080/opc-cloud-dev'
const handleCreated = (editor) => {editorRef.value = editor // 记录 editor 实例,重要!
}
type InsertFnType = (url: string, alt: string, href: string) => void
editorConfig.MENU_CONF["uploadImage"] = { //文件上传// server: "/dev-api/file/picUp/upFile",// headers: {//   Authorization: `Bearer ${getToken()}`,// },async customUpload(file: File, insertFn: InsertFnType) {  // TS 语法-自定义文件上传,用来自己写逻辑调后端接口// file 即选中的文件// 自己实现上传,并得到图片 url alt href// 最后插入图片const formData = new FormData()formData.append('file', file)uploadImage(formData).then((response) => {insertFn(url+response.data.url, 'xxxx', url+response.data.url)});}
};
</script><style lang="scss" scoped>
.app-container{height: calc(100vh - 50px);background: #EFF3F3;padding: 24px;.box {width: 100%;height: 100%;background-color: #fff;padding: 20px;.editor-tool{z-index: 999;width: 100%;height: auto;border: 1px solid #ccc;margin-bottom: 30px;}.btn {width: 100%;display: flex;justify-content: center;}}
}
</style>
<template><el-dialogv-model="isShow"title="Tips"width="1300px"><span>{{ isShow }}</span><div class="view" v-html="dialogContent"></div><el-button @click="handleQuery">确定</el-button>
</el-dialog>
</template><script lang="ts" setup>
import { ref, defineProps, computed, defineEmits, inject } from 'vue'
interface Props {myValue: booleancontent: any
}
const props = withDefaults(defineProps<Props>(), {myValue: true,content: null
})
const emits = defineEmits(['update:myValue'])
const isShow = computed({get: () => props.myValue,set: (value: any) => {emits('update:myValue', value)}
})
const dialogContent = computed({get: () => props.content,set: (value: any) => {}
})  
const handleQuery = async () => {console.log('编辑器内容', dialogContent.value);}
</script><style lang="scss" scoped></style>
http://www.lryc.cn/news/178040.html

相关文章:

  • 13.(开发工具篇github)如何在GitHub上上传本地项目
  • vue3中状态适配
  • uniapp h5 端 router.base设置history后仍有#号
  • 上网行为监管软件(上网行为管理软件通常具有哪些功能)
  • C#中的for和foreach的探究与学习
  • 【ES6知识】Promise 对象
  • 【Git】配置SSH密钥实现Git操作免密
  • AI能给百融云带来什么?
  • AI创作系统ChatGPT商业运营版源码+AI绘画/支持GPT联网提问/支持Midjourney绘画+Prompt应用+支持国内AI提问模型
  • vue.draggable拖拽,项目中三个表格互相拖拽的实例操作,前端分页等更多小技巧~
  • 400G DR4 QSFP-DD光模块:数据中心应用全攻略
  • 自动驾驶:路径规划概述
  • vlc将本地文件推流成ts实时流
  • C# 自定义控件库之Lable组合控件
  • 解密防关联指纹浏览器:联盟营销领域的秘密武器
  • asp.net core mvc Razor +dapper 增删改查,分页(保姆教程)
  • 网络安全——自学(黑客)方法
  • 秋招算法岗,面试复盘
  • AI类APP能做什么
  • 计算机毕业设计 基于SSM的垃圾分类管理系统(以医疗垃圾为例)的设计与实现 Java实战项目 附源码+文档+视频讲解
  • 友思特案例|友思特 Ensenso 3D相机:汽车工业自动化的革命性力量
  • 【5G PHY】物理层逻辑和物理天线的映射
  • MySQL如何优雅处理批量新增和更新?ON DUPLICATE KEY UPDATE用它!
  • 网络安全(加密, Hashing, 证书, SSL/TLS等)学习小结
  • 缓冲技术在嵌入式中的应用
  • vscode交叉编译cmake工程,toolchains设置
  • MATLAB算法实战应用案例精讲-【优化算法】季节优化算法(SOA)(附MATLAB代码实现)
  • DevOps持续集成与交付
  • lambda的使用案例(1)
  • nodejs+vue装修公司CRM系统设计elementui