【发布时间】:2020-12-11 18:38:04
【问题描述】:
我很好奇将 props 传递到 setup 以及根据属性更改更新变量/模板的最佳实践。
我很好奇reactive 和computed。
例如:
setup(props) {
// Setup global config settings
const config = computed(() => {
return {
// See if the component is disabled
isDisabled: props.disabled, // (1)
// Test for rounded
isRounded: props.rounded // (2)
}
})
return { config }
}
- 是否应该将
config.isDisabled和config.isRounded包装在它们自己的computed函数中,因为它们既不同又独立?但是,很容易将它们粘在一个大功能中。这方面的最佳做法是什么? - 整个
config函数是否会在函数中的单个属性更改时进行评估,还是可以识别更改并更新所需的内容? - 根据文档,
reactive具有很强的反应性并用于对象,但是,我注意到它不会更新到属性更改。因此,我在 Vue 2 中的处理方式更像是data。是我遗漏了什么还是这是正确的处理方式?
【问题讨论】:
标签: javascript vue.js vuejs3