概述
vue2封装
<template>
<div>
<slot name="label"></slot>
<input type="text" :value="modelValue" :placeholder="placeholder" @input="inpChange" @blur="blur" />
<slot name="right"></slot>
</div>
</template>
<script>
export default {
props: {
modelValue: String,
placeholder:String
},
data() {
return {};
},
methods: {
inpChange(e) {
this.$emit("input", e.target.value);
},
blur() {
this.$emit("blur");
},
},
components: {},
computed: {},
watch: {},
created() {},
};
</script>
vue3封装
<template>
<div class="header">
<input type="text" :value="modelValue" @input="input" @blur="blur" />
</div>
</template>
<script>
import { ref, reactive, toRefs, computed } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
export default {
props: {
modelValue: String,
},
setup(props, ctx) {
const store = useStore();
const router = useRouter();
const route = useRoute();
const data = reactive({
modelValue: "",
});
const input = (e) => {
ctx.emit("update:modelValue", e.target.value);
};
const blur=()=>{
ctx.emit('blur')
}
return { ...toRefs(data), input,blur };
},
};
</script>
最后
以上就是清爽中心为你收集整理的vue的input封装vue2封装vue3封装的全部内容,希望文章能够帮你解决vue的input封装vue2封装vue3封装所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复