uniapp实现一个键盘功能

news/2024/9/24 17:12:49/

前言

因为公司需要,所以我....

演示

 

代码

键盘组件代码

<template><view class="keyboard_container"><view class="li" v-for="(item, index) in arr" :key="index" @click="changArr(item)" :style="item=='删除' ? 'width: 122rpx' : item=='空格' ? 'width: 254rpx' : ''"><view>{{item}}</view></view></view>
</template><script>export default {data() {return {arr: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h","i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "u", "x", "y", "z","符", "大","删除"]};},methods: {changArr(text) {let isReturn = trueswitch(text) {case '返':this.test0()isReturn = falsebreakcase '符':this.test2()isReturn = falsebreakcase '大':this.test1()isReturn = falsebreakcase '小':this.test0()isReturn = falsebreak}isReturn ? this.$emit("onClickText", text) : ''},test0() {let arr1 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9","a", "b", "c", "d", "e", "f", "g", "h","i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "u", "x", "y", "z","符", "大","删除"]this.arr = arr1},test1() {let arr1 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9","A", "B", "C", "D", "E", "F", "G", "H","I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "U", "X", "Y", "Z","符", "小","删除"]this.arr = arr1},test2() {let arr1 = ["!", "''", "#", "$", "%", "&", "(", ")", "'", "*","+", ",", "-", ".", "/", ":", ";", "<","=",">", "?", "@", "[", "]", "\\", "^","_", "`", "{", "|", "}", "~", "空格", "返", "大","删除"]this.arr = arr1}}}
</script><style lang="scss" scoped>.keyboard_container {width: 100%;display: flex;flex-wrap: wrap;// background-color: gold;.li {font-size: 32rpx;width: 56rpx;height: 56rpx;line-height: 56rpx;margin-left: 10rpx;border-radius: 4rpx;text-align: center;color: #fff;background-color: #1890ff;}.li:active {background-color: #BBBBBB;color: #fff;}.li:first-child {margin-left: 0rpx;}.li:nth-child(9) {margin-left: 0rpx;}.li:nth-child(17) {margin-left: 0rpx;}.li:nth-child(25) {margin-left: 0rpx;}.li:nth-child(33) {margin-left: 0rpx;}.li:nth-child(n+9) {margin-top: 10rpx;}}
</style>

使用代码

<template><view class="buyCard_container"><view class="content"><view class="left"><view class="list"></view></view><view class="right"><keyboard @onClickText="clickText"></keyboard></view></view></view>
</template><script>export default {data() {return {studentNumber: '',}},onLoad() {},methods: {clickText(text) {console.log(text)if (text == '空格') {text = ' '}if (text == '删除') {this.studentNumber = this.studentNumber.substring(0,                 this.studentNumber.length - 1)return false}this.studentNumber = this.studentNumber + text}}}
</script><style lang="scss" scoped></style>


http://www.ppmy.cn/news/1474117.html

相关文章

使用paddleOCR训练自己的数据集到ONNX推理

一、环境安装 1、安装paddlepaddle&#xff1b; https://www.paddlepaddle.org.cn/ 这里安装2.6.1的话使用onnx会出现swish算子报错的问题 python -m pip install paddlepaddle-gpu2.5.2 -i https://pypi.tuna.tsinghua.edu.cn/simple验证是否成功安装 python import paddl…

自然语言处理与Transformer模型:革新语言理解的新时代

引言 自然语言处理&#xff08;NLP&#xff09;是人工智能和计算机科学的一个重要分支&#xff0c;旨在使计算机能够理解、生成和处理人类语言。随着互联网和数字化信息的爆炸性增长&#xff0c;NLP在许多领域中的应用变得越来越重要&#xff0c;包括&#xff1a; 搜索引擎&am…

机器学习统计学基础 - 最大似然估计

最大似然估计&#xff08;Maximum Likelihood Estimation, MLE&#xff09;是一种常用的参数估计方法&#xff0c;其基本原理是通过最大化观测数据出现的概率来寻找最优的参数估计值。具体来说&#xff0c;最大似然估计的核心思想是利用已知的样本结果&#xff0c;反推最有可能…

ansible常见问题配置好了密码还是报错

| FAILED! > { “msg”: “Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host’s fingerprint to your known_hosts file to manage this host.” } 怎么解决&#xf…

如何在家庭版 Windows 上安装策略组并配置 Teredo 以便在《地平线 4》和《地平线 5》中顺利进行线上匹配和多人游戏?

前言 为了确保《地平线 4》和《地平线 5》能够顺利进行线上匹配和多人游戏&#xff0c;需要在家庭版 Windows 上安装策略组并正确配置 Teredo。本文将详细介绍如何完成这些步骤。 一、安装策略组 1. 创建批处理文件 打开记事本并复制以下内容&#xff1a; echo offpushd &quo…

如何使用 uni-app 快速集成聊天会话能力?

移动互联网时代&#xff0c;即时通讯&#xff08;IM&#xff09;功能是许多app不可或缺的一部分&#xff0c;然而在即时通讯app开发时&#xff0c;开发者常常面临着选择困难&#xff1a;是为每个平台单独开发应用&#xff0c;还是有限开发某个平台&#xff1f;uni-app的出现&am…

创建react的脚手架

Create React App 中文文档 (bootcss.com) 网址&#xff1a;creat-react-app.bootcss.com 主流的脚手架&#xff1a;creat-react-app 创建脚手架的方法&#xff1a; 方法一&#xff08;JS默认&#xff09;&#xff1a; 1. npx create-react-app my-app 2. cd my-app 3. …

docker安装mysql8.0.23

拉取镜像 docker pull mysql:8.0.23 创建挂载文件 mkdir -p /home/docker/mysql/conf mkdir -p /home/docker/mysql/data mkdir -p /home/docker/mysql/logcd /home/docker/mysql/conf touch my.cnf#授权 chmod 777 -R /home/docker/mysql/conf chmod 777 -R /home/docker/m…