生活随笔
收集整理的這篇文章主要介紹了
【uni-app】rich-text 无法处理 video 的解决办法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
- Hbuilder X 2.7.14.20200618
rich-text 無法處理 video
uni-app 文檔中關于 rich-text 介紹中明確說明 rich-text 支持什么(參考這里),其中并不包含 video 。
解決辦法
在uni-app插件市場搜索parse插件使用。
parse插件有很多,包含的功能也不盡相同。
我播放 video 時使用的是uParse 富文本解析。
uParse 富文本解析插件的使用
在項目中導入插件。這步不詳述了。不會的需要補補關于uniapp的使用知識。
導入成功后,多出目錄項目根目錄/components/u-parse。在頁面中導入插件。
import uParse
from '@/components/u-parse/u-parse.vue';
替換rich-text
<u-parse :content="content" />
處理 vedio 標簽樣式
默認的vedio樣式需要修改時,可以使用正則表達式替換。
新建 js 文件 : richTextUtil.js
function formatRichText (html
) {let newContent
= html
.replace(/<img[^>]*>/gi,function(match
,capture
){match
= match
.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');match
= match
.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');match
= match
.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');return match
;});newContent
= html
.replace(/<video[^>]*>/gi,function(match
,capture
){match
= match
.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');match
= match
.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');match
= match
.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');return match
;});newContent
= newContent
.replace(/style="[^"]+"/gi,function(match
,capture
){match
= match
.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');match
= match
.replace(/font-size:[^;]+;/gi, '');return match
;});newContent
= newContent
.replace(/<br[^>]*\/>/gi, '');newContent
= newContent
.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin:0px auto;"');newContent
= newContent
.replace(/\<video/gi, '<video style="max-width:100%;height:auto;display:block;margin:0px auto;"');return newContent
;
}export default {formatRichText
,
};
引入js庫
import richTextUtil
from '@/common/richTextUtil.js';
調用方法
this.content
= richTextUtil
.formatRichText(res
.content
);
參考
https://sayyy.blog.csdn.net/article/details/107954323
總結
以上是生活随笔為你收集整理的【uni-app】rich-text 无法处理 video 的解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。