ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ivew form 表单验证自定义添加的字段 输入框只能是数字小数

2021-12-30 20:06:05  阅读:160  来源: 互联网

标签:自定义 form timer 输入框 num let chin type fn


<FormItem class="table-input" :rules="Rules" :prop="`List[${index}].name`">
	<Input size="small" :disabled="disabledAll" @input="FreqInput(tableData.List[index].name,index,'List','name',false)" v-model="tableData.List[index].name"></Input>
</FormItem>
data(){
return {
formRangeRules: [{
	required: true, type: 'string', message: "",
		validator: (rule, value, callback) => {
		...
		}
	}],}
}
methods: {
FreqInput: debounce(function (num, index, type, chin, isclear) {
	// 去掉空格
	if (num.toString().split(" ").join("").length === 0) {
		let reg = new RegExp(' ', 'g');//g,表示全部替换。
		this.tableData[type][index][chin] = num.replace(reg, '');
	} else {
		let isnmber = Number(num);
		if (isnmber || isnmber === 0) {
			if (num.substr(0, 1) === '.') {
				this.tableData[type][index][chin] = isnmber;
			}
			// 判断长度
			if (Number(num) >= 10000000) {
				if (isclear) {
					this.tableData[type][index][chin] = "";
				}
			} else {
				if (num && num.toString().includes(".")) {
					if (num.toString().split(".")[1].length > 6) {
						this.tableData[type][index][chin] = this.toFixed(num, 6)
					}
				}
			}
		} else {
			this.tableData[type][index][chin] = "";
		}
	}
}, 300),
}
		/**
		 * 函数节流
		 * @param fn
		 * @param interval
		 * @returns {Function}
		 * @constructor
		 */
	function Throttle(fn, t) {
		let last;
		let timer;
		let interval = t || 500;
		return function () {
			let args = arguments;
			let now = +new Date();
			if (last && now - last > interval) {
				clearTimeout(timer);
				timer = setTimeout(() => {
					last = now;
					fn.apply(this, args);
				}, interval);
			} else {
				last = now;
				fn.apply(this, args);
			}
		};
	}
	/**
	 * 函数防抖 (只执行最后一次点击)
	 * @param fn
	 * @param delay
	 * @returns {Function}
	 * @constructor
	 */
	function debounce(fn, t) {
		let delay = t || 500;
		let timer;
		return function () {
			let args = arguments;
			if (timer) {
				clearTimeout(timer);
			}
			timer = setTimeout(() => {
				timer = null;
				fn.apply(this, args);
			}, delay);
		};
	}		

标签:自定义,form,timer,输入框,num,let,chin,type,fn
来源: https://blog.csdn.net/qq_38946996/article/details/122244182

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有