前端插件库之vue3使用v-md-editor插件

v-md-editor

v-md-editor 是基于 Vue 开发的 markdown 编辑器组件

相关配置 – 中文文档

使用

1.命令行安装

# Vue 3 use npm
npm i @kangc/v-md-editor@next -S

2.组件中使用轻量版编辑器

<template>
  <v-md-editor
    v-model="text"
    placeholder="请使用markdown语法..."
    :height="height"
    @change="useText"
  ></v-md-editor>
</template>

<script>
import { reactive, ref, toRefs } from "vue";
export default {
  components: {},
  setup() {
    // 数据
    let text = ref(``);
    const options = reactive({ height: "400px" });

    // 方法
    function useText() {
      console.log("text:", text.value);
    }
    // 返回
    return {
      text,
      options,
      ...toRefs(options),
      useText,
    };
  },
};
</script>

<style>
</style>

2.组件中使用预览

<template>
  <v-md-preview :text="text"></v-md-preview>
</template>

<script>
export default {
  setup() {
    return {
      text: `# markdown previews
1.这里是 markdown 预览页面
      `,
    };
  },
};
</script>

3.编辑器效果–配置了代码高亮效果
在这里插入图片描述4.预览效果

在这里插入图片描述

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Vue 3 中按需引入 v-md-editor 编辑器,你可以按照以下步骤进行操作: 1. 首先,安装 v-md-editor 包及其相关依赖: ``` npm install v-md-editor @kangc/v-md-editor @kangc/v-md-editor/lib/theme/style/vuepress.css ``` 2. 在你的 Vue 3 项目中,创建一个名为 `vmdeditor.js` 的文件,用于配置按需引入: ```javascript // vmdeditor.js import { createApp } from 'vue' import VMdEditor from '@kangc/v-md-editor' import '@kangc/v-md-editor/lib/style/base-editor.css' import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js' // 引入你需要使用的编辑器组件 import { Vditor, CodeMirror, Prism, TextArea } from '@kangc/v-md-editor/lib/codemirror-editor' // 注册编辑器组件 VMdEditor.use(vuepressTheme, { Prism, CodeMirror, TextArea }) // 创建 Vue 应用实例 const app = createApp({}) app.use(VMdEditor) app.mount('#app') ``` 3. 在你的 Vue 3 项目中的入口文件(通常是 `main.js`)中引入 `vmdeditor.js` 文件: ```javascript // main.js import { createApp } from 'vue' import App from './App.vue' import './vmdeditor.js' // 引入 vmdeditor.js 文件 createApp(App).mount('#app') ``` 4. 现在,你可以在 Vue 组件中使用 v-md-editor 编辑器组件了。例如,在 `App.vue` 组件中使用 Vditor 编辑器: ```vue <template> <v-md-editor> <Vditor v-model="content" /> </v-md-editor> </template> <script> export default { data() { return { content: '' } } } </script> ``` 通过以上步骤,你可以按需引入 v-md-editor 编辑器,并在 Vue 3 项目中使用。记得根据你的需求选择合适的编辑器组件进行引入和使用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值