uniapp解析富文本視頻


rich-text無法渲染,我們可以去插件市場 找uParse 富文本解析插件進行替換
uParse 地址:uParse插件鏈接

或者獲取video的鏈接

function getVideo(data) {
let videoList = [];
let videoReg = /<video.*?(?:>|\/>)/gi; //匹配到字符串中的 video 標簽
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; //匹配到字符串中的 video 標簽 的路徑
let arr = data.match(videoReg) || []; // arr 為包含所有video標簽的數組
let articleList = data.split('</video>') // 把字符串 從視頻標簽分成數組
arr.forEach((item, index) => {
var src = item.match(srcReg);
videoList.push(src[1]) //所要顯示的字符串中 所有的video 標簽 的路徑
})
let needArticleList = [];
articleList.forEach((item, index) => {
if (item != "" && item != undefined) { // 常見的標簽渲染
needArticleList.push({
type: 'rich-text',
value: item + "</video>"
});
}
let articleListLength = articleList.length; // 插入到原有video 標簽位置
if (index < articleListLength && videoList[index] != undefined) {
needArticleList.push({
type: 'video',
value: videoList[index]
})
}
})
return needArticleList
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM