该问题的解决是通过使用 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(/<video([\s\s]*?)/g, function (match) {
const videoSrc = match.match(/src="([\S\s]*?)"/)[1];
const videoTitle = match.match(/title="([\S\s]*?)"/)[1];
return ` `;
});
}render() {
const html = '原创文章,作者:ANZSR,如若转载,请注明出处:https://www.506064.com/n/374025.html