[英]Cannot find exported component in Vuejs project
I am currently having an issue with exporting a custom Vue component from my component library package.我目前在从我的组件库包中导出自定义 Vue 组件时遇到问题。
Let's say, ComponentLib
has following folder structure, where my custom component to be exported is called icon.vue
假设, ComponentLib
具有以下文件夹结构,其中我要导出的自定义组件称为icon.vue
|-src
|-components
|-icon.vue
|-index.ts
|-package.json...and other config files
ComponetLib/src/components/icon.vue
<template functional>
...
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
import { IconModel } from '../index';
@Component({})
export default class IconComponent extends Vue {
@Prop()
icon!: IconModel;
}
</script>
ComponentLib/src/index.ts
export type IconModel = {
id: string;
content: string;
}
export { default as Icon } from 'components/icon.vue';
After building, in this dist
folder, I can see following types being exported.构建后,在这个dist
文件夹中,我可以看到以下类型被导出。
|-dist
|-...
|-types
|-components
|-icon.vue.d.ts
|-index.d.ts
|-package.json
dist/types/index.d.ts
export declare type IconModel = {
id: string;
content: string;
};
export { default as Icon } from 'components/icon.vue';
Here's the structure for MainProject
这是MainProject
的结构
|-src
|-components
|-profile.vue --> imports @ComponentLib/components/icon.vue
|-index.ts
|-package.json...and other config files
profile.vue
imports the custom icon.vue
component via profile.vue
通过以下方式导入自定义icon.vue
组件
import Icon from '@ComponentLib/types/components/icon.vue';
but when I compile, I got an error saying module not found
and it can't resolve this reference.但是当我编译时,我收到一条错误消息,提示module not found
,并且无法解析此引用。
But when I put the same component within MainProject/src/components
folder, and the compiler seems happy.但是当我将相同的组件放在MainProject/src/components
文件夹中时,编译器似乎很高兴。 It kind of occurs to me that something might be wrong with the export.我突然想到导出可能有问题。 But I am not sure which part I have missed or done wrong.但我不确定我错过或做错了哪一部分。
Apparently the way I imported the Icon component wasn't correct, and it's supposed to be like显然我导入 Icon 组件的方式不正确,它应该是这样的
import { Icon, IconModel } from '@ComponentLib/components';
And then add Icon component to @Component({components: {Icon }})
decorator.然后将 Icon 组件添加到@Component({components: {Icon }})
装饰器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.