标签:bsp date 文字 name const item html标签 hit banner
一、去除html标签及空格
1 let richText = ‘ <p style="font-size: 25px;color: white">&nbsp; &nbsp;
&nbsp; &nbsp;sdaflsjf的丰富及饿哦塞尔</p><span>dsfjlie</span>‘; 2 3 /* 去除富文本中的html标签 */ 4 /* *、+限定符都是贪婪的,因为它们会尽可能多的匹配文字,只有在它们的后面加上一个?就可以实现非贪婪或最小匹配。*/ 5 let content = richText.replace(/<.+?>/g, ‘‘); 6 console.log(content); 7 8 /* 去除&nbsp; */ 9 content = content.replace(/&nbsp;/ig, ‘‘); 10 console.log(content); 11 12 /* 去除空格 */ 13 content = content.replace(/\s/ig, ‘‘); 14 console.log(content);
二、vue中使用过滤器
1 filters: { 2 localData(value) { 3 let date = new Date(value * 1000); 4 let Month = date.getMonth() + 1; 5 let Day = date.getDate(); 6 let Y = date.getFullYear() + ‘年‘; 7 let M = Month < 10 ? ‘0‘ + Month + ‘月‘ : Month + ‘月‘; 8 let D = Day + 1 < 10 ? ‘0‘ + Day + ‘日‘ : Day + ‘日‘; 9 let hours = date.getHours(); 10 let minutes = date.getMinutes(); 11 let hour = hours < 10 ? ‘0‘ + hours + ‘:‘ : hours + ‘:‘; 12 let minute = minutes < 10 ? ‘0‘ + minutes : minutes; 13 return Y + M + D + ‘ ‘ + hour + minute; 14 } 15 } 16 17 /* 使用,直接在div中添加就可以了,| 前面的是参数,后面的是过滤器 */ 18 {{data.etime | localData}}
三、微信小程序中使用过滤器
1 var localData = function (value) { 2 var date = getDate(value * 1000); 3 var Month = date.getMonth() + 1; 4 var Day = date.getDate(); 5 var hours = date.getHours(); //计算剩余的小时 6 var minutes = date.getMinutes(); //计算剩余的分钟 7 var Y = date.getFullYear() + ‘-‘; 8 var M = Month < 10 ? ‘0‘ + Month + ‘-‘ : Month + ‘-‘; 9 var D = Day + 1 < 10 ? ‘0‘ + Day + ‘‘ : Day + ‘‘; 10 var H = hours < 10 ? ‘0‘ + hours + ‘:‘ : hours + ‘:‘ 11 var m = minutes < 10 ? ‘0‘ + minutes : minutes; 12 return Y+M + D + " " + H + m; 13 } 14 module.exports = { 15 localData: localData 16 }
四、react中使用过滤器
1 const filterImg = item => { 2 let bgImg; 3 if (item.shopimages == null) { 4 bgImg = noBanner; 5 } else { 6 bgImg = item.shopimages[0]; 7 } 8 return bgImg; 9 }; 10 /* 使用 */ 11 <img src={filterImg(storeitem)} className={style.topImg} alt="" />
标签:bsp date 文字 name const item html标签 hit banner
原文地址:https://www.cnblogs.com/harsin/p/11934684.html