子组件
<template>
<button @click="sendValueToParent">Send Value to Parent</button>
</template>
<script setup>
import { defineEmits } from 'vue'
const emit = defineEmits(['updateValue'])
function sendValueToParent() {
const value = 'Hello, Parent!'
emit('updateValue', value)
}
</script>
父组件
<template>
<ChildComponent @updateValue="handleUpdate" />
<div>Received Value: {{ receivedValue }}</div>
</template>
<script setup>
import { ref } from 'vue'
import ChildComponent from './ChildComponent.vue'
const receivedValue = ref('')
function handleUpdate(value) {
receivedValue.value = value
}
</script>
下一篇:
z-paging开启虚拟化列表