基于vue3.0和element-plus的组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.8 KiB

2 years ago
<template>
<el-input :size="state.size.size" :class="['form-item', prop.class, full && 'full']" v-model="myValue" :type="type"
1 year ago
:placeholder="placeholder || t('rule.pleaseEnter')" :disabled="disabled" :clearable="clearable">
<template v-if="label" #prepend>{{ label }}</template>
</el-input>
2 years ago
</template>
<script lang="ts" setup>
import { useStore } from "vuex";
import { onMounted, ref, watch } from "vue";
import { useI18n } from 'vue3-i18n';
const { t } = useI18n();
const { state } = useStore();
const prop = defineProps({
modelValue: null,
1 year ago
label: {
type: String,
default: null
},
2 years ago
placeholder: {
type: String,
default: null
},
class: {
type: String,
default: null
},
2 years ago
type: {
type: String,
default: null
},
disabled: {
type: Boolean,
default: false,
},
clearable: {
type: Boolean,
default: true,
},
full: {
type: Boolean,
default: false,
},
width: {
type: Number
}
});
const emit = defineEmits(["update:modelValue"]);
const myValue = ref(null);
const width = ref('150px');
const setWidth = () => {
if (prop.width) {
width.value = prop.width + 'px';
} else {
width.value = state.size.searchWidth;
}
}
watch(myValue, (n, o) => {
emit('update:modelValue', n);
})
watch(() => prop.modelValue, (n, o) => {
myValue.value = n;
})
watch(() => state.size, (n, o) => {
setWidth();
})
onMounted(() => {
prop.modelValue && (myValue.value = prop.modelValue);
setWidth();
});
</script>
<style lang="scss" scoped>
//@import url(); 引入公共css类
.form-item {
width: v-bind('width');
}
1 year ago
::v-deep .el-input-group__prepend {
min-width: 20px;
padding: 0px 4px !important;
}
2 years ago
</style>