Fri Jun 2 08:08:00 UTC 2023 inscode

上级 f5393eab
...@@ -18,3 +18,26 @@ let name = '小明' ...@@ -18,3 +18,26 @@ let name = '小明'
<style scoped> <style scoped>
</style> </style>
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'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册