wxml
<view class="payment_a">
<text>卡号:{{item.cards}}</text>
</view>
js
wx.$ajax('POST', '接口地址', {}, {}, {}).then((res) => {
if (res.code == 1) {
var lists =res.data.data
for (let i = 0; i < lists.length; i++) {
if (lists[i].card.length) {
//重要部分(replace(/(\d{4})(?=\d)/g, "$1 "))
lists[i].cards = lists[i].card.replace(/(\d{4})(?=\d)/g, "$1 ");
}
}
that.setData({
lists: lists,
})
} else {
wx.showToast({
title: res.message,
icon: 'none',
duration: 1500
})
}
},