Vue computed 声明类型时踩坑记录

computed 类型声明需要用泛型

错误写法

const a: Xx[] = computed(()=>{})

正确写法

const a = computed<Xx[]>(()=>{})

直接使用时需要加上 .value
例如

a.value

HTML 中可直接使用

:xx="a"
posted @ 2020-10-17 20:05  Leophen  阅读(812)  评论(0编辑  收藏  举报