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

VUE3封装EL-ELEMENT-PLUS input组件

VUE3封装EL-ELEMENT-PLUS input组件

完整代码

<template><div><div><div class="lable_top" v-if="label"><label :class="lable_sty">{{ label }}</label></div><el-inputv-model="inputValue"@input="emitInput":clearable="clearables":style="{ width: width }":rows="height":type="textType":class="input_sty":placeholder="placeholder":maxlength="maxlength"/></div></div>
</template><script setup>
import { ref, watch, toRefs } from "vue";
import {btKeyUpSpecChar,isChina,isNumber,isLetterAndNumber,
} from "@/utils/verification";const state = reactive({lable_sty: "lable_sty",input_sty: "input_sty",lable_width: " ",
});const { lable_sty, input_sty, lable_width } = toRefs(state);
const Rulecheck = ref(null);
const clearables = ref();
onMounted(() => {VerifyTextType();lable_width.value = props.lable_width;Rulecheck.value = props.verifyText;// 清除按钮if (props.clearable == "true") {clearables.value = true;} else if (props.clearable == "false") {clearables.value = false;} else {console.log("clearable输入有误:", props.clearable);}
});
const emit = defineEmits(["update:modelValue"]);
let props = defineProps({width: {type: String,default: "200px",},value: {type: String,default: "",},height: {type: Number,default: 1,},label: {type: String,},lable_width: {type: String,default: "100px",},placeholder: {type: String,default: "",},maxlength: {type: Number,default: 15,},verifyText: {type: String,},clearable: {type: String,default: "true",},
});// 高度
const textType = ref("text");
function VerifyTextType() {if (props.height > 1) {textType.value = "textarea";lable_sty.value = "lable_sty1";input_sty.value = "input_sty1";} else {textType.value = "text";lable_sty.value = "lable_sty";input_sty.value = "input_sty";}
}// 监听文本框输入
const inputValue = ref(props.modelValue);
watch(() => props.modelValue,(newValue) => {inputValue.value = newValue;}
);
const emitInput = () => {// 多个正则匹配if (Rulecheck.value) {var multi = Rulecheck.value.split(",");for (let index = 0; index < multi.length; index++) {switch (multi[index]) {case "isLetterAndNumber":inputValue.value = isLetterAndNumber(inputValue.value);break;case "isChina":inputValue.value = isChina(inputValue.value);break;case "isNumber":inputValue.value = isNumber(inputValue.value);break;default:break;}}}inputValue.value = btKeyUpSpecChar(inputValue.value);emit("update:modelValue", inputValue.value);
};
</script><style lang="scss" scoped>
.lable_top {display: inline-block;width: v-bind(lable_width);text-align: right;
}
.lable_sty {font-weight: normal !important;font-size: 14px;color: #606266;display: inline-block;
}
.lable_sty1 {font-weight: normal !important;font-size: 14px;color: #606266;display: inline-block;vertical-align: text-top;
}
.input_sty {margin-left: 10px;
}
.input_sty1 {margin-left: 10px;vertical-align: text-top;
}
</style>

使用

<template><div class="app-container"><general_inpuut v-model="acc" clearable="false" /><general_inpuut label="船舶编码:" v-model="acc" width="500px" /><general_inpuutlabel="测试2:"v-model="acc"width="600px"placeholder="请输入备注"maxlength="100"height="3"verifyText="isNumber"/><el-button @click="btn_change">获取值</el-button></div>
</template><script setup>
const acc = ref();function btn_change() {console.log("acc.value", acc.value);
}
</script>
http://www.lryc.cn/news/136118.html

相关文章:

  • RISC-V公测平台发布 · 在SG2042上配置Jupiter+Octave科学计算环境
  • 初识Sentinel
  • 【官方中文文档】Mybatis-Spring #注入映射器
  • UG\NX 二次开发 相切面、相邻面的选择控件
  • Quartz任务调度框架介绍和使用
  • drools8尝试
  • 【机器学习】python基础实现线性回归
  • vue table合并行 动态列名
  • Spring Cloud Alibaba-Nacos Discovery--服务治理
  • 【C++】unordered_map和unordered_set的使用 及 OJ练习
  • 初识 JVM 01
  • FPGA应用学习笔记----I2S和总结
  • 归并排序之从微观看递归
  • Pytorch-day07-模型保存与读取
  • 【C语言每日一题】01. Hello, World!
  • arm: day8
  • k8s容器加入host解析字段
  • 浅谈开发过程中完善的注释的重要性
  • Docker 微服务实战
  • JupyterHub实战应用
  • 【MySQL】视图
  • 基于 Android 剧院购票APP的开发与设计
  • 反转链表II
  • HTML 和 CSS 来实现毛玻璃效果(Glassmorphism)
  • 【技术】国标GB28181视频平台EasyGBS通过对应密钥上传到其他平台展示的详细步骤
  • SpeedBI数据可视化工具:浏览器上做分析
  • 8.21笔记
  • MyBatis-Plus中公共字段的统一处理
  • SQL的导出与导入
  • 记录一次wordpress项目的发布过程