美文网首页让前端飞uni-appWEB前端程序开发
前端Vue自定义银行卡号格式化组件 中间卡号文本转星号

前端Vue自定义银行卡号格式化组件 中间卡号文本转星号

作者: 前端组件分享 | 来源:发表于2023-06-27 07:45 被阅读0次

    前端Vue自定义银行卡号格式化组件 中间卡号文本转星号, 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13230

    效果图如下:

    # cc-format-card

    #### 使用方法

    ```使用方法

    <!-- cardNo:银行卡号 isStar: 是否转星号 -->

    <cc-format-card :cardNo="4304231999012014" :isStar="false"></cc-format-card>

    ```

    #### HTML代码实现部分

    ```html

    <template>

    <view class="content">

    <view style="margin: 30px 20px;">

    {{"不带星号银行卡号: "}}

    <!-- cardNo:银行卡号 isStar: 是否转星号 -->

    <cc-format-card :cardNo="4304231999012014" :isStar="false"></cc-format-card>

    </view>

    <view style="margin: 10px 20px;">

    {{"带星号银行卡号: "}}

    <!-- cardNo:银行卡号 isStar: 是否转星号 -->

    <cc-format-card :cardNo="4304231999012014" :isStar="true"></cc-format-card>

    </view>

    </view>

    </template>

    <script>

    export default {

    data() {

    return {

    }

    },

    methods: {

    }

    }

    </script>

    <style>

    .content {

    display: flex;

    flex-direction: column;

    background-color: white;

    height: 100vh;

    }

    </style>

    ```

    #### 组件实现代码

    ```组件实现代码

    <template>

    <text>{{value}}</text>

    </template>

    <script>

    export default {

    props: {

    cardNo: {

    type: [String, Number],

    default: ""

    },

    isStar: Boolean

    },

    computed: {

    value() {

    let cardNo = this.cardNo + "";

    if (this.isStar) {

    return `${cardNo.slice(0,4)}******${cardNo.slice(cardNo.length-4,cardNo.length)}`

    } else {

    return cardNo.replace(/\s/g, '').replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ');

    }

    }

    },

    }

    </script>

    <style>

    </style>

    ```

    相关文章

      网友评论

        本文标题:前端Vue自定义银行卡号格式化组件 中间卡号文本转星号

        本文链接:https://www.haomeiwen.com/subject/browydtx.html