类型在 Vue 组件中不可分配,但它是正确的

编程入门 行业动态 更新时间:2024-10-05 17:15:56

类型在 Vue 组件中不可分配,但<a href=https://www.elefans.com/category/jswz/34/1768103.html style=它是正确的"/>

类型在 Vue 组件中不可分配,但它是正确的

我在构建期间在 vue typescript 中输入错误。

 Type '{ [x: string]: any; name: string; parents: ...[]; id: string; createdAt: string; updatedAt: string; }[]' is not assignable to type 'Directory[]'.
  Type '{ [x: string]: any; name: string; parents: ...[]; id: string; createdAt: string; updatedAt: string; }' is not assignable to type 'Directory'.

             :directories="directories"

我的组件需要

Directory[]
作为道具:

export default defineComponent({
  name: 'Directories',
  components: {
    DeleteDialog, EditDirectoryDialog, ContextMenu, DirectoryItem,
  },
  props: {
    directories: {
      type: Array as PropType<Directory[]>,
      required: true,
    },
}

我尝试像这样从另一个组件调用这个组件:

<Directories :directories="directories" />

数据看起来像这样:

data() {
      directories: [] as Directory[],
    };

这样调用组件没有报错:

<Directories :directories="directories as Directory[]" />
回答如下:

更多推荐

类型在 Vue 组件中不可分配,但它是正确的

本文发布于:2024-05-30 15:23:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:它是   组件   分配   正确   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!