当前位置: 首页 > news >正文

vue数字输入框

目录

 1.emitter.JS

function broadcast (componentName, eventName, params) {this.$children.forEach(child => {var name = child.$options.componentNameif (name === componentName) {child.$emit.apply(child, [eventName].concat(params))} else {broadcast.apply(child, [componentName, eventName].concat([params]))}})
}export default {methods: {dispatch (componentName, eventName, params) {var parent = this.$parent || this.$rootvar name = parent.$options.componentNamewhile (parent && (!name || name !== componentName)) {parent = parent.$parentif (parent) {name = parent.$options.componentName}}if (parent) {parent.$emit.apply(parent, [eventName].concat(params))}},broadcast (componentName, eventName, params) {broadcast.call(this, componentName, eventName, params)}}
}

2.number.vue

<template><div><div class="el-number-input-wrap el-input" :class="{'is-disabled': this.inputDisabled}"><input:type="inputPositive"class="el-input__inner":id="elementId":class="inputClasses":disabled="disabled"autoComplete="off"spellcheck="false":autofocus="autofocus"@focus="handleFocus"@blur="handleBlur"@input="handleInput"@change="change":readonly="readonly || !editable":name="name":value="formatterValue":placeholder="placeholder"/></div></div>
</template>
<script>
import emitter from './emitter.js'
export default {name: 'Number',componentName: 'Number',mixins: [ emitter ],inheritAttrs: false,inject: {unForm: {default: ''},unFormItem: {default: ''}},props: {value: {type: [String, Number],default: null},max: {type: Number,default: Infinity},min: {type: Number,default: -Infinity},step: {type: Number,default: 1},activeChange: {type: Boolean,default: true},isnum: {type: Boolean,default: false},disabled: {type: Boolean,default: false},autofocus: {type: Boolean,default: false},readonly: {type: Boolean,default: false},editable: {type: Boolean,default: true},name: {type: String},precision: {type: Number},elementId: {type: String},formatter: {type: Function},parser: {type: Function},placeholder: {type: String,default: ''}},data () {return {focused: false,currentValue: this.value}},computed: {inputDisabled () {return this.disabled || (this.unForm || {}).disabled},inputClasses () {return 'el-number-input'},inputPositive () {if (this.isnum) return 'number'},precisionValue () {if (!this.currentValue) return this.currentValueif (this.precision) {var varStr = this.currentValue.toString()if (varStr.split('.').length === 1) {return this.currentValue} else {var len = varStr.split('.')[1].lengthif (len > this.precision) return this.currentValue.toFixed(this.precision)else return this.currentValue}} else {return this.currentValue}},formatterValue () {if (this.formatter && this.precisionValue !== null) {return this.formatter(this.precisionValue)} else {return this.precisionValue}},_unFormItemSize () {return (this.unFormItem || {}).unFormItemSize},validateState () {return this.unFormItem ? this.unFormItem.validateState : ''},needStatusIcon () {return this.unForm ? this.unForm.statusIcon : false},validateIcon () {return {validating: 'el-icon-loading',success: 'el-iocn-circle-check',error: 'el-icon-circle-close'}[this.validateState]}},methods: {preventDefault (e) {e.preventDefault()},setValue (val) {if (val && !isNaN(this.precision)) val = Number(val).toFixed(this.precision)if (val !== null) {if (val > this.max) {val = this.max && !isNaN(this.precision) ? Number(this.max).toFixed(this.precision) : this.max} else if (val < this.min) {val = this.min && !isNaN(this.precision) ? Number(this.min).toFixed(this.precision) : this.min}}this.$nextTick(() => {this.currentValue = valthis.$emit('input', val)this.$emit('change', val)this.dispatch('ElFormItem', 'el.form.change', val)})},handleFocus (event) {this.focused = truethis.$emit('focus', event)},handleBlur () {this.focused = falsethis.$emit('blur', event)},handleInput () {const value = event.target.valuethis.tmpValue = value},change (event) {if (event.type === 'input' && !this.activeChange) returnlet val = event.target.value.trim()if (this.parser) {val = this.parser(val)}const isEmptyString = val.length === 0if (isEmptyString) {this.setValue(null)return}// if (event.type === 'input' && val.match(/^[\+|\-]?\.?$|\.$/)) returnif (event.type === 'input' && val.match(/^[+|-]?\.?$|\.$/)) returnval = Number(val)if (!isNaN(val)) {this.currentValue = valevent.target.value = this.currentValuethis.setValue(val)} else {event.target.value = this.currentValue}},changeVal (val) {if (val === '' || val === null || val === undefined) {return}val = Number(val)if (!isNaN(val)) {const step = this.stepthis.upDisabled = val + step > this.maxthis.downDisabled = val - step < this.min} else {this.upDisabled = truethis.downDisabled = true}}},mounted () {this.changeVal(this.currentValue)},watch: {value (val) {this.currentValue = val},currentValue (val) {this.changeVal(val)},min () {this.changeVal(this.currentValue)},max () {this.changeVal(this.currentValue)}}
}
</script>

3.index.js

import Number from './src/number.vue'Number.install = function (Vue) {Vue.component(Number.name, Number)
}export default Number

4.应用

<template><div class="phone"><el-row :gutter="12"><el-col :span="12"><el-card shadow="hover"><div><h3>基础用法</h3><numbers :max="9999" :min="-9999" v-model="value1" placeholder="请输入数字"/><div style="margin-top: 20px;">要使用它,只需要在el-number元素中使用v-model绑定变量即可,变量的初始值即为默认值,如果你只需要控制数值在某一范围内,可以设置min属性和max属性,不设置时,最小值为0</div></div></el-card></el-col><el-col :span="12"><el-card shadow="hover"><div><h3>只读状态</h3><numbers :max="9999" :min="-9999" v-model="value2" placeholder="请输入数字" readonly/><div style="margin-top: 20px;">readonly属性可设置组件为只读状态</div></div></el-card></el-col></el-row><el-row :gutter="12"><el-col :span="12"><el-card shadow="hover"><div><h3>禁用状态</h3><numbers :max="9999" :min="-9999" v-model="value3" placeholder="请输入数字" disabled/></div></el-card></el-col><el-col :span="12"><el-card shadow="hover"><div><h3>精度</h3><numbers :max="9999" :min="-9999" v-model="value4" :precision="3" placeholder="请输入数字"/><div style="margin-top: 20px;">precision属性可指定输入框数字的精度</div></div></el-card></el-col></el-row><div style="margin-bottom: 20px;"><h3>Attributes</h3><el-table:data="tableData"stripeborderstyle="width: 100%"><el-table-columnprop="parameter"label="参数"width="180"></el-table-column><el-table-columnprop="instructions"label="说明"></el-table-column><el-table-columnprop="type"label="类型"width="180"></el-table-column><el-table-columnprop="optionalValue"label="可选值"width="180"></el-table-column><el-table-columnprop="defaultValue"label="默认值"width="180"></el-table-column></el-table><h3>Number Events</h3><el-table:data="tableData2"stripeborderstyle="width: 100%"><el-table-columnprop="parameter"label="事件名称"width="180"></el-table-column><el-table-columnprop="instructions"label="说明"></el-table-column><el-table-columnprop="callbackPar"label="回调参数"></el-table-column></el-table><h3>Number Methods</h3><el-table:data="tableData3"stripeborderstyle="width: 100%"><el-table-columnprop="parameter"label="方法名"width="180"></el-table-column><el-table-columnprop="instructions"label="说明"></el-table-column><el-table-columnprop="callbackPar"label="参数"></el-table-column></el-table></div></div>
</template><script>
import numbers from '../../components/number/index.js'
export default {name: 'PhoneS',components: {numbers},data () {return {value1: '',value2: '123',value3: '123',value4: '',tableData: [{parameter: 'value',instructions: '绑定值',type: 'string/number',optionalValue: '-',defaultValue: '-'},{parameter: 'placeholder',instructions: '输入框占位文本',type: 'string',optionalValue: '-',defaultValue: '-'},{parameter: 'disabled',instructions: '禁用',type: 'boolean',optionalValue: '-',defaultValue: 'false'},{parameter: 'auto-complete',instructions: '原生属性,自动补全',type: 'string',optionalValue: 'on,off',defaultValue: 'off'},{parameter: 'name',instructions: '原生属性',type: 'string',optionalValue: '-',defaultValue: '-'},{parameter: 'readonly',instructions: '原生属性,是否只读',type: 'boolean',optionalValue: '-',defaultValue: 'false'},{parameter: 'max',instructions: '原生属性,设置最大值',type: 'number',optionalValue: '-',defaultValue: 'infinity'},{parameter: 'min',instructions: '原生属性,设置最小值',type: 'number',optionalValue: '-',defaultValue: '-infinity'},{parameter: 'autofocus',instructions: '原生属性,自动获取焦点',type: 'string',optionalValue: '-',defaultValue: '-'},{parameter: 'precision',instructions: '数字精度',type: 'number',optionalValue: '-',defaultValue: '-'}],tableData2: [{parameter: 'blur',instructions: '在Number失去焦点的时候触发',callbackPar: '(event: Event)'},{parameter: 'focus',instructions: '在Number获得焦点的时候触发',callbackPar: '(event: Event)'}],tableData3: [{parameter: 'blur',instructions: '使Number失去焦点',callbackPar: '-'},{parameter: 'focus',instructions: '使Number获得焦点',callbackPar: '-'}]}},methods: {// 13213}
}
</script>

5.效果图

 

 

 

相关文章:

vue数字输入框

目录 1.emitter.JS function broadcast (componentName, eventName, params) {this.$children.forEach(child > {var name child.$options.componentNameif (name componentName) {child.$emit.apply(child, [eventName].concat(params))} else {broadcast.apply(child, …...

JavaScript—BOM

BOM是什么&#xff1f; Browser Object Model是浏览器对象模型 官方&#xff1a;浏览器对象模型提供了独立于内容的、可以与浏览器窗口进行互动的对象结构&#xff0c;BOM由多个对象构成&#xff0c;其中代表浏览器窗口的window对象是BOM的顶层对象&#xff0c;其他对象都是该…...

C# SocketException(0x2746) asp.net一个现有的连接被远程主机强行关闭

问题原因 如果网页能正常访问&#xff0c;那就是TLS版本支持的问题。 我遇到的问题是&#xff1a; 项目用的是NET Framework 4.6.1&#xff0c;但是 learn.microsoft.com 提到 NET Framework 4.6及更早版本 不支持 TLS 1.1 和 TLS 1.2。 NET Framework 4.6.2 及更高版本 支持 …...

博客系统后端(项目系列2)

目录 前言 &#xff1a; 1.准备工作 1.1创建项目 1.2引入依赖 1.3创建必要的目录 2.数据库设计 2.1博客数据 2.2用户数据 3.封装数据库 3.1封装数据库的连接操作 3.2创建两个表对应的实体类 3.3封装一些必要的增删改查操作 4.前后端交互逻辑的实现 4.1博客列表页 …...

随机化快速排序(Java 实例代码)

随机化快速排序 一、概念及其介绍 快速排序由 C. A. R. Hoare 在 1960 年提出。 随机化快速排序基本思想&#xff1a;通过一趟排序将要排序的数据分割成独立的两部分&#xff0c;其中一部分的所有数据都比另外一部分的所有数据都要小&#xff0c;然后再按此方法对这两部分数…...

JVM 垃圾收集

垃圾收集 分代理论Java 堆的内存分区不同分代收集垃圾收集算法 分代理论 弱分代假说&#xff1a;绝大多数对象都是朝生夕灭&#xff0c;即绝大多数对象都是用完很快需要销毁的。强分代假说&#xff1a;熬过多次垃圾收集过程的对象就越难以消亡&#xff0c;即如果对象经过多次垃…...

kubesphere中部署grafana实现dashboard以PDF方式导出

1&#xff0c;部署grafana-image-renderer 2&#xff0c;部署grafana GF_RENDERING_SERVER_URL http://ip:30323/render #grafana-image-renderer地址 GF_RENDERING_CALLBACK_URL http://ip:32403/ #grafana地址 GF_LOG_FILTERS rend…...

【环境配置】Android-Studio-OpenCV-JNI以及常见错误 ( 持续更新 )

最近一个项目要编译深度学习的库&#xff0c;需要用到 opencv 和 JNI&#xff0c;本文档用于记录环境配置中遇到的常见错误以及解决方案 Invalid Gradle JDK configuration found failed Invalid Gradle JDK configuration foundInvalid Gradle JDK configuration found. Open…...

js 正则表达式 验证 :页面中一个输入框,可输入1个或多个vid/pid,使用英文逗号隔开...

就是意思一个输入框里面&#xff0c;按VID/PID格式输入,VID和PID最大长度是4,最多50组 1、页面代码 <el-form ref"ruleForm" :model"tempSet" :rules"rules" label-position"right"> <!-- 最多 50组&#xff0c;每组9个字符…...

【算法与数据结构】112、LeetCode路径总和

文章目录 一、题目二、解法三、完整代码 所有的LeetCode题解索引&#xff0c;可以看这篇文章——【算法和数据结构】LeetCode题解。 一、题目 二、解法 思路分析&#xff1a;本题通过计算根节点到叶子节点路径上节点的值之和&#xff0c;然后再对比目标值。利用文章【算法和数据…...

②matlab桌面和编辑器

目录 matlab编辑器练习 运行脚本 matlab编辑器练习 您可以通过点击灰色代码框在脚本中输入命令。 准备就绪后&#xff0c;您可以通过点击蓝色的提交按钮提交代码。 任务 在脚本中输入命令 r 3。 2.任务 在脚本中添加命令 x pi*r^2。 附加练习 当您在实时编辑器中完成…...

高亮img、pdf重点部分(html2canvas、pdfjs-dist、react-pdf)

可用业务场景 报销单据审批中&#xff0c;高亮发票部分 需求 后台返回一张图片或者pdf、返回一组坐标&#xff0c;坐标类型[number,number,number,number]&#xff0c;分别代表了x、y、width、height。需要根据坐标在图片上高亮出来坐标位置。如下图 高亮的坐标是&#xff1…...

18.神奇导航菜单指示器

效果 源码 <!DOCTYPE html> <html> <head> <title>Magic Menu Indicator | 03</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body><div class="navig…...

WPF+Prism+WebApi 学习总结

一、基本概念 WPF:WPF&#xff08;Windows Presentation Foundation&#xff09;是&#xff08;微软推出的&#xff09;基于Windows的用户界面框架&#xff0c;提供了统一的编程模型&#xff0c;语言和框架&#xff0c;做到了分离界面设计人员与开发人员的工作&#xff1b;WPF…...

uniapp热更新

首先热更新需要wgt包&#xff1b; 其次先了解这两个组件 下载的方法 安装的组件 场景&#xff1a; 当你项目的js文件或者页面文件或者静态图片文件css文件更新的时候可以走热更新&#xff1b; 而当你安装新的组件插件或者开启新的权限等功能的时候就无法通过热更新进行更新了…...

AUTOSAR从入门到精通-【应用篇】基于CAN协议的汽车尾气后处理诊断系统的软件开发(续)

目录 尾气后处理诊断程序的开发 5.1 数据库的解析 5.1.1 寻找XML文件 5.1.2 读取XML文件...

mybatis plus新版代码生成器,类型转换处理器ITypeConvertHandler使用

目录 引言关键代码源码分析记录一坑类型转换的第二种方式完整源码地址 引言 当默认生成的数据类型不满足时&#xff0c;就需要自定义指定要生成的类型 关键代码 FastAutoGenerator.create(url, username, password).dataSourceConfig(builder -> {builder.typeConvertHandl…...

python中的matplotlib画直方图(数据分析与可视化)

python中的matplotlib画直方图&#xff08;数据分析与可视化&#xff09; import numpy as np import pandas as pd import matplotlib.pyplot as pltpd.set_option("max_columns",None) plt.rcParams[font.sans-serif][SimHei] plt.rcParams[axes.unicode_minus]Fa…...

【详解】文本检测OCR模型的评价指标

关于文本检测OCR模型的评价指标 前言&#xff1a;网上关于评价标准乱七八糟的&#xff0c;有关于单词的&#xff0c;有关于段落的&#xff0c;似乎没见过谁解释一下常见论文中常用的评价指标具体是怎么计算的&#xff0c;比如DBNet&#xff0c;比如RCNN&#xff0c;这似乎好像…...

Python遥感图像处理应用篇038 GDAL 遥感图像特征提取(统计特征图)

1.图像统计特征 遥感图像的统计特征是对图像中像素值的统计分布进行定量化描述的过程。这些统计特征可以提供关于图像内容和特性的有用信息。下面是一些常用的遥感图像统计特征描述方法: 平均值(Mean):计算图像中所有像素值的平均值,可以反映整个图像的亮度水平。 方差(…...

大数据学习栈记——Neo4j的安装与使用

本文介绍图数据库Neofj的安装与使用&#xff0c;操作系统&#xff1a;Ubuntu24.04&#xff0c;Neofj版本&#xff1a;2025.04.0。 Apt安装 Neofj可以进行官网安装&#xff1a;Neo4j Deployment Center - Graph Database & Analytics 我这里安装是添加软件源的方法 最新版…...

Unity3D中Gfx.WaitForPresent优化方案

前言 在Unity中&#xff0c;Gfx.WaitForPresent占用CPU过高通常表示主线程在等待GPU完成渲染&#xff08;即CPU被阻塞&#xff09;&#xff0c;这表明存在GPU瓶颈或垂直同步/帧率设置问题。以下是系统的优化方案&#xff1a; 对惹&#xff0c;这里有一个游戏开发交流小组&…...

江苏艾立泰跨国资源接力:废料变黄金的绿色供应链革命

在华东塑料包装行业面临限塑令深度调整的背景下&#xff0c;江苏艾立泰以一场跨国资源接力的创新实践&#xff0c;重新定义了绿色供应链的边界。 跨国回收网络&#xff1a;废料变黄金的全球棋局 艾立泰在欧洲、东南亚建立再生塑料回收点&#xff0c;将海外废弃包装箱通过标准…...

【论文阅读28】-CNN-BiLSTM-Attention-(2024)

本文把滑坡位移序列拆开、筛优质因子&#xff0c;再用 CNN-BiLSTM-Attention 来动态预测每个子序列&#xff0c;最后重构出总位移&#xff0c;预测效果超越传统模型。 文章目录 1 引言2 方法2.1 位移时间序列加性模型2.2 变分模态分解 (VMD) 具体步骤2.3.1 样本熵&#xff08;S…...

根据万维钢·精英日课6的内容,使用AI(2025)可以参考以下方法:

根据万维钢精英日课6的内容&#xff0c;使用AI&#xff08;2025&#xff09;可以参考以下方法&#xff1a; 四个洞见 模型已经比人聪明&#xff1a;以ChatGPT o3为代表的AI非常强大&#xff0c;能运用高级理论解释道理、引用最新学术论文&#xff0c;生成对顶尖科学家都有用的…...

用机器学习破解新能源领域的“弃风”难题

音乐发烧友深有体会&#xff0c;玩音乐的本质就是玩电网。火电声音偏暖&#xff0c;水电偏冷&#xff0c;风电偏空旷。至于太阳能发的电&#xff0c;则略显朦胧和单薄。 不知你是否有感觉&#xff0c;近两年家里的音响声音越来越冷&#xff0c;听起来越来越单薄&#xff1f; —…...

安宝特案例丨Vuzix AR智能眼镜集成专业软件,助力卢森堡医院药房转型,赢得辉瑞创新奖

在Vuzix M400 AR智能眼镜的助力下&#xff0c;卢森堡罗伯特舒曼医院&#xff08;the Robert Schuman Hospitals, HRS&#xff09;凭借在无菌制剂生产流程中引入增强现实技术&#xff08;AR&#xff09;创新项目&#xff0c;荣获了2024年6月7日由卢森堡医院药剂师协会&#xff0…...

深入浅出深度学习基础:从感知机到全连接神经网络的核心原理与应用

文章目录 前言一、感知机 (Perceptron)1.1 基础介绍1.1.1 感知机是什么&#xff1f;1.1.2 感知机的工作原理 1.2 感知机的简单应用&#xff1a;基本逻辑门1.2.1 逻辑与 (Logic AND)1.2.2 逻辑或 (Logic OR)1.2.3 逻辑与非 (Logic NAND) 1.3 感知机的实现1.3.1 简单实现 (基于阈…...

jmeter聚合报告中参数详解

sample、average、min、max、90%line、95%line,99%line、Error错误率、吞吐量Thoughput、KB/sec每秒传输的数据量 sample&#xff08;样本数&#xff09; 表示测试中发送的请求数量&#xff0c;即测试执行了多少次请求。 单位&#xff0c;以个或者次数表示。 示例&#xff1a;…...

PHP 8.5 即将发布:管道操作符、强力调试

前不久&#xff0c;PHP宣布了即将在 2025 年 11 月 20 日 正式发布的 PHP 8.5&#xff01;作为 PHP 语言的又一次重要迭代&#xff0c;PHP 8.5 承诺带来一系列旨在提升代码可读性、健壮性以及开发者效率的改进。而更令人兴奋的是&#xff0c;借助强大的本地开发环境 ServBay&am…...