我有一个接收一些道具并发出自定义事件的组件。我需要发出来将 props 的值作为参数传递。无论我做什么,我总是收到一个代理而不是原始值。这是我的实现的简化:
//child-component
<script setup lang="ts">
import { ref, unref } from "vue";
const props = defineProps<{
category: { id: number, label: string};
}>();
const emit = defineEmits(["sendcategory"]);
const category = ref(props.category);
const cat = unref(category);
function send() {
emit("sendcategory", cat);
}
<template>
<div @click="send" >
{{ category.value.label }}
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
这是父组件的示例
//parent-component
<script setup lang="ts">
import { ref } from "vue";
import ChildComponent from "./ChildComponent.vue";
const item = { id: 1, label: "testlabel" }
function getcategory(category: {id: number, …Run Code Online (Sandbox Code Playgroud)