vue2.x基于element-ui封装好玩的input输入框

在逛小米官网的时候,发现小米的输入框挺好玩的,提示文字会上下动,就自己封装了一个
image.png
<template>
  <div class="input">
    <label class="input-label" :class="{'focus':isFocus}">{{label}}</label>
    <el-input v-model="value" @focus="focusInput" @blur='blurInput' @input="change"></el-input>
  </div>
</template>

<script>
export default {
  props: ['label'],
  data() {
    return {
      isFocus: false,
      value: ""
    }
  },
  methods: {
    focusInput() {
      this.isFocus = true
    },
    blurInput() {
      if (this.value == '') {
        this.isFocus = false
      }
    },
    change() {
      this.$emit('changeValue', this.value)
    }
  }
}
</script>

<style lang="scss" scoped>
.input {
  position: relative;
  width: 100%;
  .input-label {
    position: absolute;
    left: 12px;
    top: 11px;
    z-index: 2;
    padding: 0 3px;
    font-size: 14px;
    line-height: 18px;
    color: #b0b0b0;
    background: rgba(0, 0, 0, 0);
    cursor: text;
    transition: all 0.2s linear;
  }
}
.focus {
  top: -7px !important;
  background: #fff !important;
  color: #409eff !important;
  transform: scale(0.9);
}
</style>
//引入
import InputLabel from "@/components/Common/InputLabel";
components: {
    InputLabel
 }
//使用
<InputLabel label='姓名' @changeValue='formData.username = $event' /
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容