亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

當(dāng)我在 vue 3 腳本設(shè)定中將數(shù)組作為 prop 傳遞時(shí),如何在 DefineProps 中初始化/為數(shù)組提供預(yù)設(shè)值
P粉155551728
P粉155551728 2024-03-25 18:57:15
0
1
935

我已經(jīng)傳遞了一個(gè)陣列作為道具項(xiàng),我在介面Props 中給了它一個(gè)類型,當(dāng)我嘗試給它一個(gè)預(yù)設(shè)值時(shí),我收到錯(cuò)誤第四行TS2322:類型'never[ ]'不可指派給型別'(道具:唯讀<Props>)= >字串[]'。類型“never[]”不提供與簽名“(props: Readonly<Props>): string[]”的匹配項(xiàng)。 我不確定我在這裡做錯(cuò)了什麼,因?yàn)檫@似乎適用於其他變數(shù)

<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])

P粉155551728
P粉155551728

全部回覆(1)
P粉436688931

文件

這適用於選項(xiàng) API 和組合 API!

const props = withDefaults(defineProps(), {
  items: () => []
});

複製

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板