Angular中使用Vaditor富文本编辑器
参考和体验地址:
开发文档:https://hacpai.com/article/1549638745630
体验地址:https://hacpai.com/guide/markdown
Angular中使用:
1.安装依赖:
1 | npm install vditor --save |
2.在代码中引入并初始化对象:
import Vditor from 'vditor' import "~vditor/src/assets/scss/index" const vditor = new Vditor(id, {options...})
页面中使用:
test.html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vditor/dist/index.css" /> <script src="https://cdn.jsdelivr.net/npm/vditor/dist/index.min.js" defer></script> <div id="vditor"></div> <div (click)="getEditorValue()">获取富文本编辑器里面的数据信息</div>
test.ts
import {Component, OnInit} from '@angular/core'; import Vditor from 'vditor'; @Component({ selector: 'app-testdemo', templateUrl: './testdemo.component.html', styleUrls: ['./testdemo.component.less'] }) export class TestdemoComponent implements OnInit { constructor() {} vditor: Vditor; // File:[]; ngOnInit(): void { this.vditor = new Vditor('vditor', { toolbarConfig: { pin: true, }, cache: { enable: false, }, after: () => { // this.vditor.setValue('Hello, Vditor + Angular!'); //this.vditor.setValue('<p><img src="https://jinqiaooss.oss-cn-beijing.aliyuncs.com/bxshop/2020-08-05/5f2a21b0470f5.jpg" alt="001.jpg" /><br /><img src="https://jinqiaooss.oss-cn-beijing.aliyuncs.com/bxshop/2020-08-05/5f2a21b07cb7b.jpg" alt="002.jpg" /></p>'); }, //toolbar:[], upload:{ url:"http://shop.test01.com/api/imgUpload", linkToImgUrl:"http://shop.test01.com/api/imgUpload", fieldName:"file[]", max:1048576, format:(File,msg)=>{ // console.log("============格式化拿到的数据信息File============"); let customObj={}; let dealData=JSON.parse(msg)['data']; for(let i=0;i<File.length;i++){ // console.log(File[i]['name']); customObj[File[i]['name']]=dealData[i]; } let cusObj={ "msg": "", "code": 0, "data": { // "errFiles": ['filename', 'filename2'], "succMap": customObj } } return JSON.stringify(cusObj); }, error:(res)=>{ // console.log("============上传失败返回的数据信息============"); // console.log(res); }, linkToImgCallback:(responseText)=>{ // console.log("============图片地址上传的回调数据============"); // console.log(responseText); } } }); } getEditorValue(){ console.log("============获取编辑器内容============"); console.log(this.vditor.getValue()); console.log("============获取编辑器Html内容============"); console.log(this.vditor.getHTML()); } }
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术