【发布时间】:2021-02-28 15:13:30
【问题描述】:
我想在我的 shopify 模块上添加图像,使用 react 开发,但我不知道如何导入图像。我创建了一个文件夹并在其中添加了一张图片,但我无法在我的页面中使用它。
我忘记了导入或者我写了不好的东西?
import { EmptyState, Layout, Page } from '@shopify/polaris';
import { ResourcePicker, TitleBar } from '@shopify/app-bridge-react';
import React from 'react';
import pdt from './images/pdt.png';
const img = '.images/pdt.png';
class Index extends React.Component {
state = { open: false };
render() {
return (
<Page>
<TitleBar title="Dealer De Coque - Module"/>
<h1>Module DEALER</h1>
<ResourcePicker resourceType="Product" showVariants={false} open={this.state.open} onSelection={(resources) => this.handleSelection(resources)}
onCancel={() => this.setState({ open: false })}/>
<Layout>
<EmptyState heading="Ajoutez vos produits pour débuter"
action={{
content: 'Ajouter des produits',
onAction: () => console.log('clicked'),
onAction: () => this.setState({ open: true }),
}} image={pdt} >
<p>Vous etes seulement à quelques pas de la personnalisation de produits</p>
<img src={images/pdt.png} alt="Logo" />;
</EmptyState>
</Layout>
</Page >
);
}
handleSelection = (resources) => {
const idsFromResources = resources.selection.map((product) => product.id);
this.setState({ open: false })
console.log(idsFromResources)
};
}
export default Index;
答案更新:
还是不行
也许是我的文件夹有问题?
这里是应用程序shopify页面上的错误:
【问题讨论】:
-
这行
<img src={images/pdt.png} alt="Logo" />;不应该是<img src={pdt} alt="Logo" />;吗? -
@szczocik 是的,没错。
-
@ThomasHg 欢迎来到 Stack Overflow。请看,What should I do when someone answers my question? 也可以通过tour 来熟悉如何使用这个平台。
-
@ThomasHg 你试过了吗 -
import pdt from '../images/pdt.png';
标签: javascript reactjs image directory shopify