Counter.vue
<template>
<button @click="increment">{{ count }}</button>
</template>
<script lang="ts">
import { reactive, toRefs } from "vue";
export default {
setup() {
const data = reactive({
count: 0,
increment: () => {
data.count = data.count + 1;
},
});
const refData = toRefs(data); // 解构响应式 data
return { ...refData };
},
};
</script>