Stenciljs:找不到其他组件

时间:2020-02-05 18:14:56

标签: jsx stenciljs stencil-component stencil-compiler

我已经在Stenciljs中创建了一个新项目,但是使用在该项目中创建的组件时遇到了问题。

import { Component, h, Prop } from '@stencil/core';

@Component({
    tag: 'fd-story',
    styleUrl: './story.css',
    shadow: true
})
export class Story {

    @Prop() name = '';

    render() {
        return (
            <div class="label">
                <span>{this.name}</span>
            </div>
        );
    }
}

我需要在另一个容器组件(旋转木马)中使用此组件,但是存在以下问题: enter image description here

作为解决此问题的方法,VSCode告诉我可以导入该组件,但是当我这样做时,会出现以下错误:

TypeError: Class constructor Story cannot be invoked without 'new'

我正在使用Windows10。有人发生了吗?感谢您的评论。

enter image description here

2 个答案:

答案 0 :(得分:1)

我有一个初学者的错误。我没有以正确的方式调用该组件:

 <Story
    visited={true}
    name='Comida 1'
    image='https://i.pinimg.com/originals/2a/45/af/2a45af7fa0c4347526f90ecc56e5764e.jpg'
 />

我应该这样称呼。

 <fd-story
    visited={true}
    name='Comida 1'
    image='https://i.pinimg.com/originals/2a/45/af/2a45af7fa0c4347526f90ecc56e5764e.jpg'
 />

我正在调用组件的类,但是我需要调用标签名称(fd-story)。我希望有人为之服务。

答案 1 :(得分:0)

您需要使用以下代码中的“标签”作为标签名称。

@Component({
    tag: 'fd-story',
    styleUrl: './story.css',
    shadow: true })

所以在这里您应该使用'fd-story'而不是'story'

相关问题