本文主要是介绍在nvue中富文本rich-text不显示和图片不显示的解决,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、问题:
①使用nvue展示富文本,H5端可以显示,而真机调试时却啥也不显示。
②将文件换成vue即可都展示。
<rich-text :nodes="content" style="font-size: 14px;"></rich-text>data() {return {content: `<div style="text-align:center;"><p>露从今夜白,月是故乡明</p><img src="https://cdn.uviewui.com/uview/swiper/2.jpg" style="width:550upx;height: 220upx" /></div>`}},
二、解决办法:
在common文件下新建html-parser.js文件,代码如下:
// Regular Expressions for parsing tags and attributes
var startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;
var endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/;
var attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g; // Empty Elements - HTML 5var empty = makeMap('area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr'); // Block Elements - HTML 5
// fixed by xxx 将 ins 标签从块级名单中移除var block = makeMap('a,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video'); // Inline Elements - HTML 5var inline = makeMap('abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'); // Elements that you can, intentionally, leave open
// (and which close themselves)var closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'); // Attributes that have their values filled in disabled="disabled"var fillAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'); // Special Elements (can contain anything)var special = makeMap('script,style');
function HTMLParser(html, handler) {var index;var chars;var match;var stack = [];var last = html;stack.last = function () {return this[this.length - 1];};while (html) {chars = true; // Make sure we're not in a script or style elementif (!stack.last() || !special[stack.last()]) {// Commentif (html.indexOf('<!--') == 0) {index = html.indexOf('-->');if (index >= 0) {if (handler.comment) {handler.comment(html.substring(4, index));}html = html.substring(index + 3);chars = false;} // end tag} else if (html.indexOf('</') == 0) {match = html.match(endTag);if (match) {html = html.substring(match[0].length)
这篇关于在nvue中富文本rich-text不显示和图片不显示的解决的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!