问题描述
我想实现以下说我作为MD
md:'#H1'
我想把它渲染成
<h1>H1</h1>
我能够使用 VueShowdown
实现这一目标<h1 class="custom">H1</h1>
我得到了类似于这个 here 的东西。
但我不知道如何在 Vue 中使用它。
甚至可以在 VueShowdown 中使用吗?
有没有更好的库有这个功能?
解决方法
您可以创建一个简单的指令:
Vue.directive('default-classes',(parentElement) {
const els = parentElement.querySelectorAll('h1')
els.forEach((el) => {
el.classList.add('custom')
})
})
然后将该指令应用于 VueShowdown
组件:
<VueShowdown v-default-classes :markdown="markdownBinding" />