[英]change computed based on another computed in vue 3
I have this in vue 3. I need to change the title using the prop id if is 0 should be 'New' else 'Details' based on another computed property that I have editMode我在 vue 3 中有这个。我需要使用 prop id 更改标题,如果是 0 应该是 'New' else 'Details' 基于我有 editMode 的另一个计算属性
setup(props) {
const {id} = toRefs(props)
const editMode = computed(() => {
return id.value !== 0
})
const title = computed(() => {
return editMode ? 'Details' : 'New'
})
}
the problem is when editMode is false the title is not changing ..... remains 'Details' all the time.问题是当 editMode 为 false 时,标题不会改变......一直保持“详细信息”。
Any idea ?任何的想法 ?
I think you need to alter editMode
to editMode.value
inside title compute, given editMode
also belongs to Ref type.我认为您需要在标题计算
editMode
editMode.value
更改为editMode.value
,因为editMode
也属于 Ref 类型。
const title = computed(() => {
return editMode.value ? 'Details' : 'New'
})
This should simply solve your problem.这应该可以简单地解决您的问题。
Also try console.log(typeof id.value)
to ensure String '0'
and Number 0
are not mixed up.还可以尝试
console.log(typeof id.value)
以确保 String '0'
和 Number 0
不会混淆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.