Install# Using npm npm i @kangc/v-md-editor@next -S # Using yarn yarn add @kangc/v-md-editor@next Importing componentsimport { creatApp } from 'vue'; import VMdEditor from '@kangc/v-md-editor'; import '@kangc/v-md-editor/lib/style/base-editor.css'; import githubTheme from '@kangc/v-md-editor/lib/theme/github.js'; import '@kangc/v-md-editor/lib/theme/style/github.css'; VMdEditor.use(githubTheme); const app = creatApp(/*...*/); app.use(VMdEditor); Basic usage<template> <v-md-editor v-model="text" height="400px"></v-md-editor> </template> <script> import { ref } from 'vue'; export default { setup () { const text = ref(''); return { text } } } </script> How to render the saved markdown or html text on the page?1. Render the saved markdown text Method 1: If you have introduced an editor into your project. You can render directly using the editor's preview mode. For example <template> <v-md-editor :value="markdown" mode="preview"></v-md-editor> </template> <script> import { ref } from 'vue'; export default { setup () { const markdown = ref(''); return { Markdown } } } </script> Method 2: If your project does not require editing functionality and only needs to render markdown text, you can only introduce the preview component for rendering. For example // main.js import { creatApp } from 'vue'; import VMdPreview from '@kangc/v-md-editor/lib/preview'; import '@kangc/v-md-editor/lib/style/preview.css'; // Import the theme you are using. Here we take the github theme as an example. import githubTheme from '@kangc/v-md-editor/lib/theme/github'; import '@kangc/v-md-editor/lib/theme/style/github.css'; VMdPreview.use(githubTheme); const app = creatApp(/*...*/); app.use(VMdPreview); <template> <v-md-preview :text="markdown"></v-md-preview> </template> <script> import { ref } from 'vue'; export default { setup () { const markdown = ref(''); return { Markdown } } } </script> 2. Render the saved HTML text If your project does not require editing functionality and only needs to render HTML, you can just import the preview-html component for rendering. For example: // main.js import { creatApp } from 'vue'; import VMdPreviewHtml from '@kangc/v-md-editor/lib/preview-html'; import '@kangc/v-md-editor/lib/style/preview-html.css'; // Import the style of the theme import '@kangc/v-md-editor/lib/theme/style/vuepress'; const app = creatApp(/*...*/); app.use(VMdPreviewHtml); <template> <!-- preview-class is the style class name of the theme, for example, vuepress is vuepress-markdown-body --> <v-md-preview-html :html="html" preview-class="vuepress-markdown-body"></v-md-preview-html> </template> <script> import { ref } from 'vue'; export default { setup () { const html = ref('<div data-v-md-line="1"><h1 align="center">Markdown Editor built on Vue</h1>'); return { html } }, }; </script> For more advanced usage, refer to the official documentation: v-md-editor The above is the details of how to use the markdown editor component in Vue3. For more information about using the markdown editor component in Vue3, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: MySQL constraint types and examples
>>: How to connect to MySQL visualization tool Navicat
In Vue, we can define (register) local components...
When creating a MySQL container with Docker, some...
The test environment of this experiment: Windows ...
Normally, when a deadlock occurs, the connection ...
First create a directory cd /etc/nginx mkdir ssl ...
Table of contents 1. The principle of index push-...
This article shares with you the installation tut...
Table of contents 1. Install Docker 2. Install Gi...
Ubuntu does not allow root login by default, so t...
This is the effect to be achieved: You can see th...
Recently I was looking at how Docker allows conta...
Table of contents 1. Simple retrieval of data 2. ...
How to install flash in Linux 1. Visit the flash ...
I would like to share with you the graphic tutori...
First, let me explain the version of MySQL: mysql...