百度小程序bdparse解决rich-text富文本无法渲染video视频

1、下载bdparse源码:https://gitee.com/sootou/bdparse

将bdparse包放在小程序根目录下:

3、在swan页面引入 <import src="../../../bdParse/bdParse.swan" />

4、css页面引入 @import "../../../bdParse/bdParse.css";

5、js页面引入 var bdParse = require('../../../bdParse/bdParse.js');

6、在js需要的字段处使用  bdParse.bdParse('questionTitle', 'html', this.data.question.title, this, 0);

注意:bdparse只能解析字符串,其他数据类型会报错!!!

7、如果需要在循环体内使用bdparse,需要在data中声明一个数组  optionContents: []

getMedia() {
        // 标题
        this.data.question.title = this.initGetImgSrc(this.data.question.title);
        this.data.question.title = this.initGetVideoSrc(this.data.question.title);
        bdParse.bdParse('questionTitle', 'html', this.data.question.title, this, 0);
        // 选项
        this.data.question.contents.forEach((cont, index) => {
            this.data.optionContents.push(index);
            cont.content = this.initGetImgSrc(cont.content);
            cont.content = this.initGetVideoSrc(cont.content);
            bdParse.bdParse(`optionContents[${index}]`, 'html', cont.content, this, 0)
        });
        this.setData({
            question: this.data.question
        });
    },

swan页面引用:

<template is="bdParse" data="{{{ bdParseData: optionContents[index].nodes }}}" />

参考博客:百度小程序富文本解析工具bdParse_微齐天大圣.的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值