sdaflsjf的丰富及饿哦塞尔

dsfjlie'; /*去除富文本中的html标签*/ /**、+限定符都是贪婪的,因为它们会尽可能多的匹配文字,只有在它们的后面加上一个?就可以实现非贪婪或最小匹配。*/ letcontent=richText.replace(/<.+?>/g,''); console.log(content); /*去除 */ content=content.replace(/ /ig,''); console.log(content); /*去除空格*/ content=content.replace(/\s/ig,''); console.log(content);

截取字符串

content=formatRichText(content);
console.log(content);
/*使用substring来截取字符串*/
if(content.length>10){
content=content.substring(0,10)+'...';
}
console.log(content);
/*限制字数后添加省略号*/
functionformatRichText(richText){
lettemporaryText='';
/*设置多长后添加省略号*/
constlen=142;
if(richText.length*2<=len){
returnrichText;
}
/*用于记录文字内容的总长度*/
letstrLength=0;
for(leti=0;i128){
strLength=strLength+2;
if(strLength>=len){
returntemporaryText.substring(0,temporaryText.length-1)+"...";
}
}else{
strLength=strLength+1;
if(strLength>=len){
returntemporaryText.substring(0,temporaryText.length-2)+"...";
}
}
}
returntemporaryText;
}

2.vue中使用过滤器

filters:{
localData(value){
letdate=newDate(value*1000);
letMonth=date.getMonth()+1;
letDay=date.getDate();
letY=date.getFullYear()+'年';
letM=Month<10?'0'+Month+'月':Month+'月';
letD=Day+1<10?'0'+Day+'日':Day+'日';
lethours=date.getHours();
letminutes=date.getMinutes();
lethour=hours<10?'0'+hours+':':hours+':';
letminute=minutes<10?'0'+minutes:minutes;
returnY+M+D+''+hour+minute;
}
}

/*使用,直接在div中添加就可以了,|前面的是参数,后面的是过滤器*/
{{data.etime|localData}}

3.微信小程序中使用过滤器

新建.wxs文件

varlocalData=function(value){
vardate=getDate(value*1000);
varMonth=date.getMonth()+1;
varDay=date.getDate();
varhours=date.getHours();//计算剩余的小时
varminutes=date.getMinutes();//计算剩余的分钟
varY=date.getFullYear()+'-';
varM=Month<10?'0'+Month+'-':Month+'-';
varD=Day+1<10?'0'+Day+'':Day+'';
varH=hours<10?'0'+hours+':':hours+':'
varm=minutes<10?'0'+minutes:minutes;
returnY+M+D+""+H+m;
}
module.exports={
localData:localData
}

使用,用标签来引入,src为路径,module为引入的文件模块名


{{tool.filterScore(item.shop.score)}}分

直接在.wxml文件中用包裹


varsome_msg="helloworld";
module.exports={
msg:some_msg,
}

{{foo.msg}}

4.react中使用

react中使用,其实就是定义一个方法

importnoBannerfrom'@/assets/storeDetail/no-banner.jpg'
constfilterImg=item=>{
letbgImg;
if(item.shopimages==null){
bgImg=noBanner;
}else{
bgImg=item.shopimages[0];
}
returnbgImg;
};
/*使用*/

总结

以上所述是小编给大家介绍的如何去除富文本中的html标签及vue、react、微信小程序中的过滤器,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!

热门推荐

1 书法中考祝福语大全简短
2 领证祝福语弟弟的话简短
3 新人祝福语宝宝文案简短
4 虎年征婚祝福语简短精辟
5 祝福语 祝愿朋友诗句简短
6 保研的祝福语简短
7 入学面试祝福语大全简短
8 大外甥高考祝福语简短
9 送礼长辈搬家祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短