使用mp-html 插件
1、在项目下安装
npm install mp-html
2、开发者工具中勾选 使用 npm 模块 并点击 工具 - 构建 npm
3、在需要使用页面的 json 文件中添加
{
"usingComponents": {
"mp-html": "mp-html"
}
}
4、在需要使用页面的 wxml 文件中添加
<mp-html content="{{html}}" />
5、a 标签数据格式
this.data.html="<a class="link" href="https://www.baidu.com">链接</a>"
6、a标签跳转链接自定义,copy-url 设置为false,使用linktap 监听事件
<mp-html content="{{item.content}}" bindlinktap="linktap" copy-link="{{false}}" tag-style="{{tagStyle}}"/>
7、a标签事件监听
linktap(e){
console.log(e.detail.href)
}
8、a标签样式统一设置
tagStyle:{ a: 'color:#007AFF;text-decoration: underline;'},
9 、效果
1746588339935.png