根据单据:
如果不需要访问实际的对象实例,可以将其封装在
reactive
:中nested: reactive({ count, })
无法理解这个提示,有人能提供一个真实世界的例子吗?
我同意这个提示似乎没有什么意义。
基于引入提示的提交中的更改,我认为这意味着:
如果不想打开模板中的值,可以将值包装在
setup()
中的reactive
中。
也就是说,以下代码:
export default {
setup() {
const count = ref(0)
return {
nested: {
count
}
}
}
}
需要在模板中显式展开:
<template> 👇
<div>{{ nested.count.value }}</div>
</template>
但是在这里的嵌套对象周围使用reactive()
:
export default {
setup() {
const count = ref(0)
return { 👇
nested: reactive({
count
})
}
}
}
允许模板不那么冗长:
<template>
<div>{{ nested.count }}</div>
</template>