一个分块input组件
<template>
<view class="line">
<view class="wrapper" v-for="(item, index) in inputBox" :key="index">
<input
class="input"
v-model="item.value"
type="text"
:focus="item.focus"
@input="onInput(index)"
maxlength="1"
/>
</view>
</view>
</template>
<script>
export default {
name: 'SplitInputBox',
model: {
prop: 'value',
event: 'change',
},
props: {
digit: {
type: Number,
default: 4,
},
},
data() {
return {
inputBox: [{ value: '', focus: true }],
}
},
methods: {
onInput(index) {
const value = this.inputBox[index].value
if (value.length === 1 && index < this.$props.digit - 1) {
this.inputBox[index].focus = false
this.inputBox[index + 1].focus = true
} else if (value.length === 0 && index > 0) {
this.inputBox[index].focus = false
this.inputBox[index - 1].focus = true
} else {
this.inputBox[index].focus = false
return
}
},
},
computed: {
fullValue: {
get: function () {
let value = ''
this.inputBox.forEach((item) => {
value += item.value
})
return value
},
set: function (newValue) {
const values = newValue.split('')
if (values.length !== this.$props.digit) {
console.warn(`Error: new value should be at least ${this.$props.digit} digits`)
return
}
for (let i = 0; i < values.length; i++) {
this.inputBox[i] = values[i]
}
},
},
},
watch: {
fullValue(nv) {
this.$emit('change', nv)
},
},
created() {
if (this.$props.digit < 1) console.warn('Error: digit should be at least 1')
const unit = { value: '', focus: false }
for (let i = 0; i < this.$props.digit - 1; i++) {
this.inputBox.push(JSON.parse(JSON.stringify(unit)))
}
},
}
</script>
<style lang="less" scoped>
.line {
width: 100%;
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
.wrapper {
padding: 0 24rpx;
.input {
width: 80rpx;
height: 80rpx;
border: 2rpx solid #333333;
border-radius: 16rpx;
background: #ffffff;
text-align: center;
}
}
}
</style>
#明日方舟 《明日方舟》x《彩虹六号:围攻》联动结束纪念
我跟着你的战术走过,你看透了一切。
辛苦了,干得漂亮。
https://api.2heng.xin/bilibili/og.php?av=972238419&danmaku=0
https://t.bilibili.com/505201579803310407
好是好看,可是就没几个人玩瑶啊,为什么不出个阿古朵皮肤
Happy Birthday curl 🎉
Daniel Stenberg: This day 23 years ago, I uploaded the first ever curl release. Happy birthday to all of us who use and appreciate curl. I love you all.
https://daniel.haxx.se/blog/2021/03/20/curl-is-23-years-old-today/
I always find tomorrow, but tomorrow is not a place. Tomorrow is you.
我终其一生去寻找一个名叫明天的地方,却发现明天不是一个地方,而是你。
#DailyEnglish #每日英语
关注了
//转发自: @银大友: 【彩虹六号】整活! 小葵成名录 15【VOICEROID实况】
更新啦更新啦!小葵成名录15来力来力~
顺便求个三连~
https://api.2heng.xin/bilibili/og.php?av=886779415&danmaku=0
https://t.bilibili.com/504068838017867245
太强了。。。前段时间看了一遍svg文档结果回头来都没记住
生如夏花 (朴树 翻唱) / 药师寺寛邦 kissaquo
JavaScript for impatient programmers
Chinese 🇨🇳 / Dictatorial Admin / Mastodon Code Contributor / 摸鱼技术布道师
Steam: https://steamcommunity.com/id/MashiroBest
Epic: https://store.epicgames.com/en-US/u/d211c824cbd94aaeba898db6bb823ff7
原批交流群:966322309