import { reactive, toRefs } from 'vue' function myFunction() { const state = reactive({ foo: 'bar' }) function updateFoo(newFoo) { state.foo = newFoo } return { ...toRefs(state), updateFoo } } // 在函数外部使用 const { foo, updateFoo } = myFunction() console.log(foo.value) // 输出:'bar' updateFoo('new value') console.log(foo.value) // 输出:'new value'