方法一:
如果子组件使用跳转的方法
const navigateToRegion=()=>{
uni.navigateTo({
url: '/pagesD/components/selpow/selpow'
});
}
中/pagesD/components/selpow/selpow传递uni.$emit('selectedLabels', checkedKeys.value); 如何接收?
<script setup lang="ts">
import { ref, onMounted,onUnmounted } from 'vue';
const handleBack = () => {
uni.navigateBack();
};
const navigateToRegion = () => {
uni.navigateTo({
url: '/pagesD/components/selpow/selpow'
});
};
// 监听selectedLabels事件
const onSelectedLabels = (labels) => {
console.log('Received labels:', labels);
};
onMounted(() => {
// 监听全局事件
uni.$on('selectedLabels', onSelectedLabels);
});
// 组件卸载时,移除事件监听
onUnmounted(() => {
uni.$off('selectedLabels', onSelectedLabels);
});
</script>