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

vue3+naiveUI二次封装的v-model 联动输入框

根据官网说明使用

请添加图片描述

源码

<template><div class="clw-input pt-3"><n-inputref="input":value="modelValue":type="type":title="title"clearable:disabled="disabled":size="size"placeholder=""@focus="$emit('focus')"@blur="blur"@input="input"@change="change"/><label class="z-1 text-warmgray" :style="style">{{ placeholder }}</label></div>
</template><script>
/*** @author        全易* @time          2022-10-11 13:08:46  星期二* @description   自定义输入框组件**/export default {name: 'ClwInput',props: {placeholder: {type: String,default: '',},// 父组件v-model绑定的值modelValue: {type: String,default: '',},size: {type: String,default: 'medium',},disabled: {type: Boolean,},labelBG: {type: String,default: '#ffffff',},labelColor: {type: String,default: '#19aa8d',},type: {type: String,default: '',},},emits: ['focus', 'blur', 'change', 'update:modelValue'],data() {return {inputHeight: null,style: {},}},computed: {title() {return `${this.placeholder}${this.modelValue}`},},watch: {modelValue: {deep: true,handler() {this.resetStyle()},},},mounted() {this.inputHeight = this.$refs.input.$el.offsetHeightthis.resetStyle()},methods: {blur() {this.resetStyle()this.$emit('blur')},input(val) {this.resetStyle()this.$emit('update:modelValue', val)},change(val) {this.$emit('change', val)},resetStyle() {if (this.modelValue) {this.style = {transform: `translateY(${-(this.inputHeight / 2)}px)`,color: `${this.labelColor} !important`,'background-color': this.labelBG,padding: '0 10px',}} else {this.style = {bottom: `${this.inputHeight * 0.18}px`,}}},},
}
</script><style lang="scss" scoped>
.clw-input {position: relative;label {position: absolute;left: 15px;pointer-events: none;transition: all 0.3s ease;}
}
</style>

使用

<clw-inputv-model="queryForm.propertyNo"placeholder="物业编号"@keydown.enter="getData"></clw-input>
http://www.lryc.cn/news/289136.html

相关文章:

  • 百度Apollo | 实车自动驾驶:感知、决策、执行的无缝融合
  • DAY31:贪心算法入门455、53、376
  • LeetCode:376.摆动序列
  • Stable Diffusion插件Recolor实现黑白照片上色
  • Android 音频焦点管理
  • 大模型+自动驾驶
  • openssl3.2 - 测试程序的学习 - test\aesgcmtest.c
  • C语言——操作符详解2
  • (免费领源码)java#Springboot#mysql旅游景点订票系统68524-计算机毕业设计项目选题推荐
  • 帝国cms7.5 支付升级优化版文库范文自动生成word/PDF文档付费复制下载带支付系统会员中心整站模板源码sitemap百度推送+安装教程
  • 【node】关于npm、yarn、npx的区别与使用
  • 力扣0099——恢复二叉搜索树
  • 机器学习核心算法
  • libjsoncpp 的编译和交叉编译
  • 【Unity美术】如何用3DsMax做一个水桶模型
  • 如何用一根网线和51单片机做简单门禁[带破解器]
  • 在 VUE 项目中,使用 Axios 请求数据时,提示跨域,该怎么解决?
  • 1.【Vue3】前端开发引入、Vue 简介
  • 一起学习ETCD系列——运维操作之etcdctl使用
  • Spring Security 存储密码之 JDBC
  • 第3章-python深度学习——(波斯美女)
  • 蓝桥杯备战——4.继电器/蜂鸣器
  • Redis高级特性之地理空间索引
  • R语言【taxlist】——as():将 taxlist 对象强制转换为 list 对象
  • 使用POI生成word文档的table表格
  • C# 继承、多态性、抽象和接口详解:从入门到精通
  • python在线聊天室(带聊天保存)
  • jenkins+gitlab实现Android自动打包填坑之旅
  • 洛谷B3625迷宫寻路
  • GPT-SoVITS 测试