首页 > 其他分享 >md-editor-v3适配VUE3的MarkDown编辑器-好用-简单-免费

md-editor-v3适配VUE3的MarkDown编辑器-好用-简单-免费

时间:2024-08-16 15:55:06浏览次数:17  
标签:md MarkDown const 适配 v3 editor res import

 官方文档:

https://imzbf.github.io/md-editor-v3/zh-CN/indexicon-default.png?t=N7T8https://imzbf.github.io/md-editor-v3/zh-CN/index

效果演示:(支持黑暗模式切换)

toolbar包括:

[
  'bold',
  'underline',
  'italic',
  'strikeThrough',
  'title',
  'sub',
  'sup',
  'quote',
  'unorderedList',
  'orderedList',
  'codeRow',
  'code',
  'link',
  'image',
  'table',
  'revoke',
  'next',
  'save',
  'pageFullscreen',
  'fullscreen',
  'preview',
  'htmlPreview',
  'github'
];

 简单使用:
 

npm install md-editor-v3
<md-editor v-model="text" @on-upload-img="onUploadImg" />

<script setup lang="ts">
import { ref } from 'vue'
import MdEditor from 'md-editor-v3'
import 'md-editor-v3/lib/style.css'

const text = ref('Hello Editor!')
const onUploadImg = (files: any) => {
  console.log(files)
}
</script>

上传图片可以参考:

async onUploadImg(files: FileList, callback: (urls: string[]) => void) {
  const res = await Promise.all(
    Array.from(files).map((file) => {
      return new Promise((rev, rej) => {
        const form = new FormData();
        form.append('file', file);

        axios
          .post('/api/img/upload', form, {
            headers: {
              'Content-Type': 'multipart/form-data'
            }
          })
          .then((res) => rev(res))
          .catch((error) => rej(error));
      });
    })
  );

  callback(res.map((item: any) => item.data.url));
}

仅预览模式:

<template>
  <MdPreview :editorId="id" :modelValue="text" />
  <MdCatalog :editorId="id" :scrollElement="scrollElement" />
</template>

<script setup>
import { ref } from 'vue';
import { MdPreview, MdCatalog } from 'md-editor-v3';
// preview.css相比style.css少了编辑器那部分样式
import 'md-editor-v3/lib/preview.css';

const id = 'preview-only';
const text = ref('# Hello Editor');
const scrollElement = document.documentElement;
</script>

标签:md,MarkDown,const,适配,v3,editor,res,import
From: https://blog.csdn.net/qq_35204012/article/details/141217072

相关文章