在vue项目中有时候会使用到v-html,而在mpvue中,也有代替品mpvue-wxparse。
1、安装mpvue-wxparse
2、使用,详情可见官网 https://github.com/F-loat/mpvue-wxParse
<template>
<div>
<wxParse :content="article" @preview="preview" @navigate="navigate" />
</div>
</template>
<script>
import wxParse from 'mpvue-wxparse'
export default {
components: {
wxParse
},
data () {
return {
article: '<div>我是HTML代码</div>'
}
},
methods: {
preview(src, e) {
// do something
},
navigate(href, e) {
// do something
}
}
}
</script>
<style>
@import url("~mpvue-wxparse/src/wxParse.css");
</style>
本文介绍如何在mpvue项目中使用mpvue-wxparse组件来解析并显示HTML内容。通过安装mpvue-wxparse并按官方文档进行配置,可以实现在小程序中渲染复杂的HTML结构。
1643





