首页 > 编程知识 正文

Taro3.5.11版本微信小程序端v-html依然无法解析video为中心的问题解决方案

时间:2023-11-19 09:32:30 阅读:290679 作者:PQJM

该问题的解决是通过使用 Taro3.5.11 版本自定义组件进行处理,具体解决方案如下:

一、自定义组件

首先,我们需要创建一个自定义组件 VideoComponent,该组件的主要目的是将 v-html 内的 video 标签转换成 Taro 可识别的 video 标签,示例代码如下:

import Taro, { Component } from '@tarojs/taro';
import { View, Video } from '@tarojs/components';

class VideoComponent extends Component {
  static defaultProps = {
    videoSrc: '',
    videoTitle: ''
  };

  constructor(props) {
    super(props);
  }

  render() {
    const { videoSrc, videoTitle } = this.props;
    return (
      
        
      
    );
  }
}

export default VideoComponent;

二、v-html 内 video 标签转换

接下来,在需要使用 v-html 属性的组件内引入 VideoComponent 组件,并使用正则表达式将 video 标签转换成 VideoComponent 组件的形式,示例代码如下:

import Taro, { Component } from '@tarojs/taro';
import { View, RichText } from '@tarojs/components';
import VideoComponent from '../../components/video-component';

class TestPage extends Component {
  constructor(props) {
    super(props);
  }

  convertVideoTagToComponent = (html) => {
    return html.replace(//g, function (match) {
      const videoSrc = match.match(/src="([Ss]*?)"/)[1];
      const videoTitle = match.match(/title="([Ss]*?)"/)[1];
      return ` `;
    });
  }

  render() {
    const html = ' 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。