[Vue 04] Vue slot
예
예준천
<script setup>
import child from './child';
</script>
<template>
<child v-slot="slotProps" >
<input v-model="slotProps.data[0]"/>
<input v-model="slotProps.data[1]"/>
<input v-model="slotProps.data[2]"/>
<input v-model="slotProps.data[3]"/>
</child>
</template>
<style scoped>
</style><script setup>
import {ref} from 'vue';
const data = ref([]);
</script>
<template>
<slot :data="data">
</slot>
</template>
<style scoped>
</style><script setup>
import child from './child';
const idValid // ...
const pwValid // ...
const nameValid // ...
const birthValid // ...
</script>
<template>
<child v-slot="slotProps" :validationArray="[idValid,pwValid,nameValid,birthValid]">
<input v-model="slotProps.data[0]"/>
<input v-model="slotProps.data[1]"/>
<input v-model="slotProps.data[2]"/>
<input v-model="slotProps.data[3]"/>
</child>
</template>
<style scoped>
</style><script setup lang="ts">
import {ref} from 'vue';
const data = ref([]);
const result = ref();
const props = defineProps<{validationArr: Array<()=>boolean>}>();
const validAll = ()=>{
result.value = props.validationArr.some((validation,idx) => !validation(data[idx]));
}
</script>
<template>
<slot :data="data">
</slot>
<button @click="validAll">값 검증하기</button>
</template>
<style scoped>
</style><script setup>
import child from './child';
</script>
<template>
<child v-slot="slotProps">
<customInput v-model="slotProps.data[0].value" ref="slotProps.data[0].refAnchor"/>
</child>
</template>
<style scoped>
</style><script setup>
import {ref} from 'vue';
const data = ref( Array.from({ length: 60 }, () => ({value:ref('') , refAnchor: ref(null) }) ));
const validate = () =>{
data.forEach((input) =>{
input.refAnchor.value.validation(input.value);
});
};
</script>
<template>
<slot :data="data">
</slot>
</template>
<style scoped>
</style><script setup lang="ts">
const props = defineProps<{value:string}>();
const emits = defineEmits<{(event:'update:value',value:string):void}>();
const validation = () => {
return true;
}
defineExpose({validation});
</script>
<template>
<input :value="props.value" @input="$event.target.value"/>
</template>
<style scoped>
</style><script setup>
import child from './child';
const data =ref();
</script>
<template>
<child v-model:data="data">
<customInput />
<customInput />
<customInput />
<customInput />
<customInput />
</child>
</template>
<style scoped>
</style><script setup>
import {ref} from 'vue';
const data = ref( Array.from({ length: 60 }, () => ({value:'' , refAnchor: ref() }) ));
// 1. 현재 부모 컴포넌트에 마운트된 자식 vnode를 확인한다.
// 2. 자식 vnode들에 대해 값 가져오기 & validation 메소드 가져오기
</script>
<template>
<slot :data="data">
</slot>
</template>
<style scoped>
</style><script setup lang="ts">
inteface passwordInputProps{
data
}
inteface passwordInputEmits{
(event:'update:value',value:string):void;
(event:'isInvalid',isInvalid:boolean):void;
}
const props = defineProps<passwordInputProps>();
const emits = defineEmits<passwordInputEmits>();
</script>
<template>
<input :value ="props."
</template>
<style scoped>
</style>