WoJ*_*WoJ 4 typescript vue.js vuejs3 vue-composition-api
我正在尝试学习 Vue3 + Typescript(到目前为止我用纯 JS 编写了 Vue2 应用程序)。我试图在以下位置定义一个反应变量setup()
:
setup() {\n // a single note\n interface Note {\n id: string\n creationDate: string\n text: string\n tags: string[]\n deleted: boolean\n }\n // all the notes in the app\n let allNotes: ref(Note[]) // \xe2\x86\x90 this is not correct\n let allnotes: Note[] // \xe2\x86\x90 this is correct but not reactive\n \n (...)\n }\n
Run Code Online (Sandbox Code Playgroud)\n创建反应式数组的正确语法是什么Note
?
Bou*_*him 15
它应该放在<>
:
let allNotes= ref<Note[]>([])
Run Code Online (Sandbox Code Playgroud)
默认情况下,ref
从初始值推断类型,例如
const name=ref('') //name is a type of string
Run Code Online (Sandbox Code Playgroud)
参考输入:
interface Ref<T> {
value: T
}
function ref<T>(value: T): Ref<T>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8736 次 |
最近记录: |