mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-20 00:06:47 +08:00
-- 项目名称校验
This commit is contained in:
58
src/components/project/NameInput.vue
Normal file
58
src/components/project/NameInput.vue
Normal file
@@ -0,0 +1,58 @@
|
||||
<template>
|
||||
<a-input
|
||||
v-model:value="modelV"
|
||||
placeholder="请输入项目名称"
|
||||
:show-count="showCount"
|
||||
:maxlength="maxlength"
|
||||
@blur="validateProName"
|
||||
/>
|
||||
<div style="color:red;font-size: 10px" v-if="value && !validate">名称重复,请重新输入</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import {defineProps, defineEmits, watch, ref} from "vue";
|
||||
import {validateName} from "@/api/index1";
|
||||
|
||||
const props = defineProps({
|
||||
value: {
|
||||
type: String,
|
||||
},
|
||||
validate: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
type: {
|
||||
type: Number,
|
||||
default: 1
|
||||
},
|
||||
maxlength: {
|
||||
type: Number,
|
||||
default: 30
|
||||
},
|
||||
showCount: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits({})
|
||||
|
||||
const modelV = ref()
|
||||
|
||||
watch(() => props.value, () => {
|
||||
if (props.value !== modelV.value) {
|
||||
modelV.value = props.value
|
||||
}
|
||||
})
|
||||
|
||||
watch(modelV, () => {
|
||||
emit('update:value', modelV.value)
|
||||
})
|
||||
|
||||
function validateProName() {
|
||||
console.log(props.value)
|
||||
props.value && validateName({name: props.value, type: props.type}).then(res => {
|
||||
emit('update:validate', res.data.data !== 1)
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user