const getCateList = async ( ) => { const res = await fetchCateList () as any if (res. code == 200 ) { this . cateList = res. data

res已经定义了any类型,但是cateList的类型还没有定义,默认为never

1、方式一 (TS断言 尖括号语法)

data: {
    cateList: <any>[]

2、方式二 (TS断言 as语法)

data: {
    cateList: [] as any

3、方式三 (TS接口 interface)

//接口返回的数据结构如下
res.data = [
{id:'1',name:'xxx',level:1},
{id:'2',name:'xxx',level:2},
{id:'3',name:'xxx',level:3}
//根据返回的数据结构定义对应的类型
interface ICateList {
  id: string
  name: string
  level:number