const formState = reactive({
associTag:"",
dynamicTags:[]
})
function confirmAdd(){
if(formState.dynamicTags.length==0 || formState.dynamicTags.indexOf(formState.associTag)==-1){
formState.dynamicTags.push(formState.associTag);
}
}
刚学习ts,报错确实让人很头疼
dynamicTags
没定义类型,默认是Array<never>
。假设你里面要放的元素是类型
Foo
,那么声明时需要:几种写法都可以,推荐第一种。