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

网站后台无法更新缓存做网站纸张大小

网站后台无法更新缓存,做网站纸张大小,南山网站公司定,中国焊接外包加工网Vue2 实现el-input带输入限制的动态表格,限制输入位数以及输入规则(负数、小数、整数) 在这个 Vue2 项目中,我们实现一个限制输入位数(整数16位,小数10位)以及输入规则(负数、小数、…

Vue2 实现el-input带输入限制的动态表格,限制输入位数以及输入规则(负数、小数、整数)

在这个 Vue2 项目中,我们实现一个限制输入位数(整数16位,小数10位)以及输入规则(负数、小数、整数),并提供了处理用户输入的方法。以下是代码的解释:

var num = this.inputLimit(e, 16, 10, scope, index);

参数解释:

e: 事件对象,代表触发函数的输入事件,通常用于获取事件相关信息,如输入值。

16: 整数部分的最大允许位数,作为 intMax 在 inputLimit 函数中使用,用于限制整数部分的长度。

10: 小数部分的最大允许位数,作为 dotMax 在 inputLimit 函数中使用,用于限制小数部分的长度。

scope: 代表 Vue 模板中的 slot-scope 对象,通常用于访问表格中正在迭代的行的属性。

index: 当前迭代的循环索引,通常用于确定当前项目在数组或列表中的位置。

总结一下:

e: 输入事件对象。
16: 整数部分的最大位数。
10: 小数部分的最大位数。
scope: Vue 模板中的 slot-scope 对象,用于访问表格中的行数据。
index: 当前迭代的循环索引。
inputLimit 函数的设计旨在基于提供的约束条件(整数部分长度、小数部分长度)限制输入,并处理各种场景,如负数。返回的 num 可能是经过处理和限制的输入值。

完整代码:

<template><div class="hello"><el-table v-loading="loading" :data="versionList" height="calc(100vh - 270px)" size="small"><el-table-column label="名称" align="center" prop="name" :show-overflow-tooltip="true" width="200" /><el-table-column v-for="(item, index) in fillYear" :key="item" :label="item" align="center" :prop="item" width="200":show-overflow-tooltip="true"><template slot-scope="scope"><el-input type="text" v-model="scope.row.fillData[index].value" @change="handleInput($event, scope, index)" /></template></el-table-column></el-table></div>
</template><script>
export default {name: "HelloWorld",data() {return {loading: false,fillYear: ["2019", "2020", "2021", "2022"],versionList: [{name: "书包",fillData: [{ key: "2019", value: "" },{ key: "2020", value: "" },{ key: "2021", value: "" },{ key: "2022", value: "" },],},{name: "铅笔",fillData: [{ key: "2019", value: "" },{ key: "2020", value: "" },{ key: "2021", value: "" },{ key: "2022", value: "" },],},{name: "橡皮",fillData: [{ key: "2019", value: "" },{ key: "2020", value: "" },{ key: "2021", value: "" },{ key: "2022", value: "" },],},{name: "玩具",fillData: [{ key: "2019", value: "" },{ key: "2020", value: "" },{ key: "2021", value: "" },{ key: "2022", value: "" },],},],};},methods: {handleInput(e, scope, index) {// 获取用户输入的值// let inputValue = scope.row.fillData[index].value;// 使用正则表达式检查输入值是否为数字或小数// let regex = /^[0-9]+(\.[0-9]{0,2})?$/;// 如果不匹配正则表达式,则清除非法字符// if (!regex.test(inputValue)) {//     inputValue = inputValue.replace(/[^\d.]/g, '');// 更新绑定的值//     this.$set(scope.row.fillData, index, { ...scope.row.fillData[index], value: inputValue });// }var num = this.inputLimit(e, 16, 10, scope, index);console.log(`🚀>> ${num}`)},inputLimit(num, intMax, dotMax, scope, index) {if (num === undefined || num === null) {return '0';}var next = num.toString();var hasCompany = next.startsWith('-');next = hasCompany ? next.substring(1) : next;if (next.includes('.')) {// 小数var [intNum, dotNum] = next.split('.').map(part => part.replace(/[^0-9]/g, ''));next = `${intNum}.${dotNum}`;this.$set(scope.row.fillData, index, { ...scope.row.fillData[index], value: `${hasCompany ? '-' : ''}${next}` });} else {// 非小数next = next.replace(/[^0-9]/g, '');this.$set(scope.row.fillData, index, { ...scope.row.fillData[index], value: `${hasCompany ? '-' : ''}${next}` });}if (Number(next)) {var resNum = '';if (next.includes('.')) {var [intPart, dotPart] = next.split('.');// 限制整数位数16、小数10位intPart = intPart.substring(0, intMax);dotPart = dotPart.substring(0, dotMax);resNum = Number(`${intPart}.${dotPart}`).toFixed(dotPart.length);} else {resNum = next.substring(0, intMax);}this.$set(scope.row.fillData, index, { ...scope.row.fillData[index], value: `${hasCompany ? '-' : ''}${resNum}` });return resNum;}return '0';},},created() {console.log(this.versionList);},
};
</script><!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped></style>

效果图如下:
输入非整数、小数、负数,且包含其他字符或非法数字的,change事件之后会处理为正常的数据
在这里插入图片描述

http://www.yayakq.cn/news/54134/

相关文章:

  • 购物网站黑白网站如何做的看起来高大上
  • 香山网站建设中卫网站制作公司报价
  • 制作网站免费网站被人做跳转
  • 网站建设推广怎么玩新网站如何让百度收录
  • wordpress中英文站点windows优化大师的特点
  • 南昌网站建设和推广分类目录搜索引擎
  • 苏州本地网站网站上线验收
  • 网站动态图标怎么建设一个网站营口地区承办方
  • 电子产品网站建设分析的摘要wordpress纯文本
  • 做网站小程序在哪点拉客户设计师培训怎么样
  • 福建网站建设推广企业网站的标题关键词
  • 贵阳自助建站软件百度收录最快网站
  • 无锡网站营销公司哪家好net网站开发做手工简笔
  • 个人网站备案号可以做企业网站吗建设银行网站钓鱼网站
  • 如何申请一个免费的网站空间做网站费用会计科目
  • 网站建设运营招聘汽车logo设计图片创意
  • 常州辉煌网络网站建设wordpress 照片墙代码
  • 免费微网站开发平台网站内页跳转wap
  • 腾讯wordpress 建站购买模板建站
  • 广陵区建设局网站网络搭建国赛题
  • 贵阳网站建设在线上海网站制作公司怎么找
  • 专门做单页的网站重庆网站定制公司
  • 做医院网站公司吗互联网营销方案策划
  • 企业网站制作 深圳wordpress linux密码
  • 站长百度贵州省住房和城乡建设部网站
  • 公司网站背景图片销售单页网站
  • 淘宝网站建设概要推广网站模板
  • 华池网站建设中国建设工程电子信息网
  • 数据展示网站免费注册域名网站知乎
  • 网站认证方式有几种wordpress 赢利模式