UNIAPP - filters传多个值

UNIAPP不支持filters传输多个形参值 ,但可以支持传输对象

 

 

 1 <template>
 2     <view>
 3     <view class="fix-list" v-for="(item, index) in mockList" :key="index">
 4             <view class="fix-list-item" @click="handlePhone">
 5                 <view>手机号码</view>
 6                 <view style="color: #409EFE;">{{ item | phoneVal }}</view>
 7             </view>
 8         </view>
 9     </view>
10 </template>
11 
12 <script>
13 export default {
14     data() {
15         return {
16             mockList: [{ mobile: '13111225554', tag: 1 }, { mobile: '13254565421', tag: 2 }]
17         };
18     },
19     filters: {
20         phoneVal(item) {
21             if (item.tag == 1) {
22                 return hidePhone(item.mobile);
23             } else {
24                 return item.mobile;
25             }
26             // 通过形参传过来的对象(item)即可继续走下面的逻辑 , 判断标识tag:1即可显示完整号码,否则隐藏中间4位数
27         }
28     },
29     methods: {
30         
31     }
32 };
33 
34 
35 </script>
36 
37 <style lang="scss">
38 
39 </style>
40     

 

1 const hidePhone = cellValue => {
2     if (Number(cellValue) && String(cellValue).length === 11) {
3         let mobile = String(cellValue);
4         let reg = /^(\d{3})\d{4}(\d{4})$/;
5         return mobile.replace(reg, '$1****$2');
6     } else {
7         return cellValue;
8     }
9 };

 

posted @ 2020-10-15 16:49  Sunsin  阅读(1930)  评论(0编辑  收藏  举报