最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

uniapp+vue3實(shí)現(xiàn)自定義封裝支付密碼組件

 更新時(shí)間:2025年08月18日 11:11:58   作者:Pinia_0819  
本文介紹使用Vue3語(yǔ)法在uniapp中自定義封裝支付密碼組件,通過(guò)父組件與子組件的交互實(shí)現(xiàn)密碼輸入功能,并附效果圖展示,感興趣的朋友跟隨小編一起看看吧

使用uniapp自定義封裝支付密碼組件(vue3語(yǔ)法)

父組件

<paypassword v-model="passwordValue" @complete="onPasswordComplete"></paypassword>
const passwordValue = ref('')
// 密碼輸入完成回調(diào)
const onPasswordComplete = (password) => {
  console.log('密碼輸入完成:', password)
  passwordValue.value = password;
  uni.showToast({
    title: '密碼輸入完成',
    icon: 'success'
  })
}

子組件

<template>
    <view class="password-container">
      <!-- 第一行:6個(gè)密碼輸入框 -->
      <view class="password-input-container">
        <view class="password-input-row">
          <view 
            v-for="index in 6" 
            :key="index"
            class="password-input-box"
            :class="{ 'active': currentIndex === index - 1 }"
          >
            <view v-if="password[index - 1]" class="password-dot"></view>
          </view>
        </view>
      </view>
      <!-- 第二行:狀態(tài)圖標(biāo)和文字 -->
      <view class="password-status">
        <uni-icons 
          :type="isCompleted ? 'checkbox-filled' : 'checkbox-filled'" 
          :color="isCompleted ? '#12a58c' : '#d4d4d4'"
          size="32rpx"
        ></uni-icons>
        <text 
          class="status-text" 
          :class="{ 'status-text-complete': isCompleted }"
        >
          {{ '6個(gè)數(shù)字' }}
        </text>
      </view>
      <!-- 第三模塊:12宮格數(shù)字鍵盤(pán) -->
      <view class="number-keyboard">
        <view class="keyboard-row" v-for="(row, rowIndex) in keyboardLayout" :key="rowIndex">
          <view 
            v-for="(key, keyIndex) in row" 
            :key="keyIndex"
            class="keyboard-key"
            @click="handleKeyClick(key)"
          >
            <text v-if="key.type === 'number'" class="key-text">{{ key.value }}</text>
            <!-- 移除按鈕可以使用icon,也可以使用自定義圖片我使用的是自定義圖片 -->
           <!-- <uni-icons 
              v-if="key.type === 'delete'" 
              type="closeempty" 
              size="56rpx" 
              color="#171717"
            ></uni-icons> -->
            <image class="delImg" v-if="key.type === 'delete'"  src="/static/image/home/Frame.png" mode=""></image>
          </view>
        </view>
      </view>
    </view>
  </template>
  <script setup>
  import { ref, computed, watch, defineProps, defineEmits } from 'vue'
  // 定義props
  const props = defineProps({
    // 提示文字
    tipText: {
      type: String,
      default: '請(qǐng)輸入6位數(shù)字密碼'
    },
    // 初始密碼值
    modelValue: {
      type: String,
      default: ''
    }
  })
  // 定義emits
  const emits = defineEmits(['update:modelValue', 'complete'])
  // 數(shù)據(jù)狀態(tài)
  const password = ref([])
  const currentIndex = ref(0)
  // 鍵盤(pán)布局
  const keyboardLayout = [
    [
      { type: 'number', value: '1' },
      { type: 'number', value: '2' },
      { type: 'number', value: '3' }
    ],
    [
      { type: 'number', value: '4' },
      { type: 'number', value: '5' },
      { type: 'number', value: '6' }
    ],
    [
      { type: 'number', value: '7' },
      { type: 'number', value: '8' },
      { type: 'number', value: '9' }
    ],
    [
      { type: 'number', value: '*' },
      { type: 'number', value: '0' },
      { type: 'delete'}
    ]
  ]
  // 計(jì)算屬性:是否輸入完成
  const isCompleted = computed(() => password.value.length === 6)
  // 監(jiān)聽(tīng)密碼完成狀態(tài)
  watch(isCompleted, (newVal) => {
    if (newVal) {
      const passwordStr = password.value.join('')
      emits('update:modelValue', passwordStr)
      emits('complete', passwordStr)
    }
  })
  // 監(jiān)聽(tīng)modelValue變化
  watch(() => props.modelValue, (newVal) => {
    if (newVal && newVal.length <= 6) {
      password.value = newVal.split('')
      currentIndex.value = password.value.length
    }
  }, { immediate: true })
  // 處理按鍵點(diǎn)擊
  const handleKeyClick = (key) => {
    if (key.type === 'number') {
      // 輸入數(shù)字
      if (password.value.length < 6) {
        password.value.push(key.value)
        currentIndex.value = password.value.length
      }
    } else if (key.type === 'delete') {
      // 刪除
      if (password.value.length > 0) {
        password.value.pop()
        currentIndex.value = password.value.length
      }
    }
    // 更新modelValue
    const passwordStr = password.value.join('')
    emits('update:modelValue', passwordStr)
  }
  // 重置密碼
  const resetPassword = () => {
    password.value = []
    currentIndex.value = 0
  }
  // 暴露方法給父組件
  defineExpose({
    resetPassword
  })
  </script>
  <style lang="scss" scoped>
  .password-container {
    width: 100%;
    padding-top: 96rpx;
    box-sizing: border-box;
    .password-input-container {
      margin-bottom: 32rpx;
      .password-input-row {
        display: flex;
        justify-content: space-between;
        .password-input-box {
          width: 96rpx;
          height: 112rpx;
          border-radius: 24rpx;
          border: 2rpx solid #171717;
          display: flex;
          align-items: center;
          justify-content: center;
          &.active {
            border-color: #FF4001;
          }
          .password-dot {
            width: 20rpx;
            height: 20rpx;
            border-radius: 50%;
            background: #333;
          }
        }
      }
    }
    .password-status {
      display: flex;
      align-items: center;
      margin-bottom: 40rpx;
      .status-text {
        font-family: PingFang SC, PingFang SC;
        font-size: 24rpx;
        color: #737373;
        margin-left: 8rpx;
      }
      .status-text-complete {
        color: #12a58c;
      }
    }
    .number-keyboard {
      .keyboard-row {
        display: flex;
        justify-content: space-around;
        margin-bottom: 20rpx;
        .keyboard-key {
            width: 207rpx;
            height: 112rpx;
            background: #FAFAFA;
            border-radius: 24rpx;
            display: flex;
            align-items: center;
            justify-content: center;
          .key-text {
            font-family: PingFang SC, PingFang SC;
            font-weight: 500;
            font-size: 48rpx;
            color: #171717;
          }
          .delImg {
              width: 56rpx;
              height: 56rpx;
          }
          &.key-delete {
            // background: #e0e0e0;
          }
          &.key-empty {
            // background: transparent;
            // visibility: hidden;
          }
        }
      }
    }
  }
  </style>

效果圖:

到此這篇關(guān)于uniapp+vue3實(shí)現(xiàn)自定義封裝支付密碼組件的文章就介紹到這了,更多相關(guān)vue自定義支付密碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解Vue.js之視圖和數(shù)據(jù)的雙向綁定(v-model)

    詳解Vue.js之視圖和數(shù)據(jù)的雙向綁定(v-model)

    本篇文章主要介紹了Vue.js之視圖和數(shù)據(jù)的雙向綁定(v-model),使用v-model指令,使得視圖和數(shù)據(jù)實(shí)現(xiàn)雙向綁定,有興趣的可以了解一下
    2017-06-06
  • 深入理解vue中slot與slot-scope的具體使用

    深入理解vue中slot與slot-scope的具體使用

    這篇文章主要介紹了深入理解vue中slot與slot-scope的具體使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • Vue項(xiàng)目中scrollIntoView導(dǎo)致的布局異常問(wèn)題解決辦法

    Vue項(xiàng)目中scrollIntoView導(dǎo)致的布局異常問(wèn)題解決辦法

    scrollIntoView的實(shí)現(xiàn)原理是通過(guò)調(diào)整滾動(dòng)容器的滾動(dòng)位置,使目標(biāo)元素在視口中可見(jiàn),這篇文章主要介紹了Vue項(xiàng)目中scrollIntoView導(dǎo)致的布局異常問(wèn)題解決辦法的相關(guān)資料,需要的朋友可以參考下
    2026-04-04
  • 9種方法優(yōu)化jQuery代碼詳解

    9種方法優(yōu)化jQuery代碼詳解

    本文將詳細(xì)介紹jQuery代碼優(yōu)化的9種方法,需要的朋友可以參考下
    2020-02-02
  • Vue Router中獲取路由傳遞過(guò)來(lái)的參數(shù)(方法詳解)

    Vue Router中獲取路由傳遞過(guò)來(lái)的參數(shù)(方法詳解)

    在VueRouter中,可以通過(guò)動(dòng)態(tài)路由匹配和查詢參數(shù)`query`來(lái)傳遞參數(shù),并將路由參數(shù)或查詢參數(shù)作為組件的`props`傳遞,動(dòng)態(tài)路由匹配使用`route.params`訪問(wèn)參數(shù),查詢參數(shù)使用`route.query`訪問(wèn),本文給大家介紹Vue Router中獲取路由傳遞過(guò)來(lái)的參數(shù),感興趣的朋友一起看看吧
    2025-02-02
  • 詳解Vue爬坑之vuex初識(shí)

    詳解Vue爬坑之vuex初識(shí)

    本篇文章主要介紹了詳解Vue爬坑之vuex初識(shí) ,Vue 的狀態(tài)管理工具 Vuex可以解決大型項(xiàng)目中子組件之間傳遞數(shù)據(jù),有興趣的可以了解下
    2017-06-06
  • vue樣式疊層z-index不起作用的解決方案

    vue樣式疊層z-index不起作用的解決方案

    這篇文章主要介紹了vue樣式疊層z-index不起作用的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • Vue使用虛擬鍵盤(pán)及中英文切換功能

    Vue使用虛擬鍵盤(pán)及中英文切換功能

    這篇文章主要給大家介紹了關(guān)于Vue使用虛擬鍵盤(pán)及中英文切換的相關(guān)資料,有時(shí)候在大型觸屏設(shè)備(如雙屏設(shè)備)中往往就沒(méi)有鍵盤(pán)去操作,所以就需要去建立一個(gè)虛擬鍵盤(pán)去操作,需要的朋友可以參考下
    2023-06-06
  • vue中實(shí)現(xiàn)點(diǎn)擊空白區(qū)域關(guān)閉彈窗的兩種方法

    vue中實(shí)現(xiàn)點(diǎn)擊空白區(qū)域關(guān)閉彈窗的兩種方法

    這篇文章主要介紹了vue中實(shí)現(xiàn)點(diǎn)擊空白區(qū)域關(guān)閉彈窗的兩種方法,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2020-12-12
  • 組件中多個(gè)el-upload存在導(dǎo)致上傳圖片失效的問(wèn)題及解決

    組件中多個(gè)el-upload存在導(dǎo)致上傳圖片失效的問(wèn)題及解決

    這篇文章主要介紹了組件中多個(gè)el-upload存在導(dǎo)致上傳圖片失效的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03

最新評(píng)論

孝义市| 文化| 孝感市| 施秉县| 延庆县| 平凉市| 和田市| 南部县| 荥阳市| 南陵县| 郧西县| 永顺县| 曲周县| 延长县| 即墨市| 神池县| 台中县| 博爱县| 东光县| 洛川县| 涟源市| 苍溪县| 堆龙德庆县| 平遥县| 蒙自县| 石阡县| 鸡泽县| 达尔| 松滋市| 都江堰市| 东丽区| 邯郸县| 武山县| 和林格尔县| 沐川县| 永川市| 瑞金市| 灌云县| 绍兴县| 育儿| 井陉县|