首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >v-for项目类型未知。

v-for项目类型未知。
EN

Stack Overflow用户
提问于 2022-10-12 15:55:32
回答 1查看 135关注 0票数 -1

在VS代码中,类型记录会抛出错误。很明显,物品的型号不明。但是它呈现得很好,控制台中没有错误或警告。我该如何消除这些错误呢?

代码语言:javascript
复制
<script setup lang="ts">
    import NavLink from '@/Components/NavLink.vue';
    import { PropType } from 'vue'

    interface Item {
        href: String,
        active: Boolean,
        text: String
    }

    const props = defineProps({
        items : {
            type: Object as PropType<Item[]>,
            required: true
        }
    });
</script>

<template>
  <nav class="navbar navbar-expand-lg">
            <div class="container">
                <a class="navbar-brand" href="{{route('dashboard')}}">Page title</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                        <NavLink v-for="(item, key, index) in items" :href="item.href" :active="item.active" :key="index">
                            {{item.text }}
                        </NavLink>
                    </ul>
                </div>
            </div>
        </nav>
</template>

错误:

'unknown'.

  • Property‘’
  • 属性'href‘在类型 'active’上不存在,在类型‘’ 'text‘上不存在。
EN

回答 1

Stack Overflow用户

发布于 2022-10-13 03:45:58

你的密码很奇怪。

items道具被声明为type: Object as PropType<Item[]> -所以运行时类型( Vue用来处理道具的信息)是对象,但是输入info表示它是一个数组。似乎不正确,而且可能是Volar (Vue VS COde语言服务)困惑的原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74044766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档