我已经传递了一个数组作为道具项,我在接口 Props 中给了它一个类型,当我尝试给它一个默认值时,我收到错误第四行 TS2322:类型'never[]'不可分配给类型'(道具:只读<Props>)= >字符串[]'。类型“never[]”不提供与签名“(props: Readonly<Props>): string[]”的匹配项。 我不确定我在这里做错了什么,因为这似乎适用于其他变量
<script setup lang="ts">
import {ref} from "vue";
interface Props {
items?: Array<string>
}
const props = withDefaults(defineProps<Props>(), {
items: []
});
let selectedItem = ref(props.items[0]) Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
文档
这适用于选项 API 和组合 API!
复制