微信小程序物流信息数据中手机号样式添加
1.首先物流信息的数据是从后台获取的,样式部分见下一章,这里主要讲解一下手机号样式
2.在微信小程序中新建一个wxs的文件,主要的精华在这里(有兴趣的童靴可以自己学一下wxs语法)
var getMax = function(text) {
if(!text){
return false;
}
var reg =getRegExp('1[345789]\d{9}','g');//验证是否是手机号
var phone=reg.exec(text);
return text.replace(getRegExp('1[0-9]{10}','g'),"<span style='color:#489EFF;border-bottom:1px solid #489EFF'>"+phone+"</span>");//手机号颜色更改
}
module.exports.way = getMax;
3.在页面中用rich-text组件,(注意要先在wxml文件中引用此wxs文件)再调用刚刚封装好的wxs
<wxs src="../../utils/format.wxs" module="format" />
<rich-text nodes="{{format.way(item.context)}}"></rich-text>
4.这样就欧凯啦