简体   繁体   English

如何在 vue3 的 props 中使用嵌套数组?

[英]How to use nested arrays in props in vue3?

I'm using SFC and a setup script with Vue3 (and typescript), and I can't seem to create a prop that's a nested array:我正在使用 SFC 和带有 Vue3(和打字稿)的设置脚本,我似乎无法创建一个嵌套数组的道具:

const props = defineProps({
    title: String,
    desc: String,
    columns: Array<Array<String>>,
});

The answer is in https://vuejs.org/api/sfc-script-setup.html#typescript-only-features答案在https://vuejs.org/api/sfc-script-setup.html#typescript-only-features

The syntax for typescript is different:打字稿的语法不同:

const props = defineProps<{
  foo: string
  bar?: number
}>()

I think that you would be looking at something like this.我想你会看到这样的东西。

const props = defineProps<{
  title: string;
  desc: string;
  columns: string[][];
}>()

If you are using optional props I would also recommend looking at withDefaults .如果您使用的是可选道具,我还建议您查看withDefaults

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM