我正在努力学习Vue3 +打字本(到目前为止,我用普通的JS编写了Vue2应用程序)。我试图在setup()中定义一个反应性变量:
setup() {
// a single note
interface Note {
id: string
creationDate: string
text: string
tags: string[]
deleted: boolean
}
// all the notes in the app
let allNotes: ref(Note[]) // ← this is not correct
let allnotes: Note[] // ← this is correct but not reactive
(...)
}创建Note的反应性数组的正确语法是什么
发布于 2021-06-03 14:17:53
它应该放在<>之间:
let allNotes= ref<Note[]>([]) 默认情况下,ref从初始值推断类型,如
const name=ref('') //name is a type of string参考打字:
interface Ref<T> {
value: T
}
function ref<T>(value: T): Ref<T>发布于 2021-06-03 14:21:51
不需要为该对象创建一个反应性对象。
类似@Boussadjra Brahim说,向ref函数添加一个类型,如下所示
let reactiveNoteArray = ref<Note[]>([]); //Add this angle bracket when using custom types and interfaceshttps://stackoverflow.com/questions/67823122
复制相似问题