vue 复习 v-model 自己实现,如此简单

<template>
  <div>
    <input :type="type" :value="value" @input="myinput" />
  </div>
</template>

<script>
export default {
  props: {
    type: {
      type: String,
      default: "text",
    },
    value: {
      type: String,
      default: "",
    },
  },
  methods: {
    myinput(ev) {
      this.$emit("input", ev.target.value);
    },
  },
};
</script>

<style scoped>
</style>

KInput 组件

使用起来非常简单

只要实现了value 和@input 就可以实现v-model 了

猜你喜欢

转载自blog.csdn.net/qq_15009739/article/details/107575263
今日推荐