【发布时间】:2019-07-13 00:24:30
【问题描述】:
我正在尝试将图像插入到使用 Stencil 构建的 Web 组件中。
我收到 2 个错误:
AppLogo is declared but its value is never read.
和
Cannot find module ../assets/logo.svg.
目录:
- src
-- components
--- app-header
---- assets
----- logo.svg
---- app-header.tsx
---- app-header.scss
---- app-header.spec.ts
代码:
import { Component } from "@stencil/core";
import AppLogo from "../assets/logo.svg";
@Component({
tag: "app-header",
styleUrl: "app-header.scss"
})
export class AppHeader {
render() {
return (
<header class="app-header">
<a href="#" class="app-logo">
<img src="{AppLogo}" alt="App Name" />
</a>
</header>
);
}
}
这方面的文档并不多(我可以找到)。因此,任何帮助表示赞赏。
【问题讨论】:
-
你不能这样声明Applogo吗:
var Applogo = "../assets/logo.svg"? -
我认为我不需要将其设为变量。我需要先导入它,然后它应该加载...但是我在导入时遇到模块未找到错误。
-
只能导入JS文件AFAIK
-
阅读本文,看看是否有帮助:stackoverflow.com/questions/54708824/…
标签: html jsx web-component stenciljs stencil-component