- 单一元素声明
let cars:string[];
cars = ["BYD", "WuLing", "HongQi"];
- 多维数组声明
let cars:string[][];
cars = [["BYD", "WuLing", "HongQi"], ['LiXiang', 'WeiLai', 'XiaoPeng'] ];
- 元素为对象的复杂数据
interface ObjType {
key: string;
title: string;
}
interface TabArr {
key: string;
title: string;
children: ObjType[];
}
方式一:
const tabArr: TabArr[] = [
{
key: 'key-1',
title: '标题一',
children: [],
},
{
key: 'key-2',
title: '标题二',
children: [
{
key: 'key2-2',
title: '标题二-2',
},
],
},
];
方式二:
let tabArr = ref<TabArr>([] as TabArr);