Vue 中使用 markdown
注意项目使用 CLI3+创建
首先安装 marked 插件
使用 npm
npm install marked -S
使用 yarn
yarn add marked
在组件中引入 marked
<template>
<div v-html="md"></div>
</template>
<script>
//引入marked
const marked = require('marked')
export default {
data() {
return {
md: ''
}
},
created() {
// 调用marked函数,传入markdown格式的内容,返回一段html
this.md = marked('# Vue 中使用 markdown')
}
}
</script>