Ken428965 2022-09-06 20:26 采纳率: 53.4%
浏览 48
已结题

react,使用swiper走马灯组件,如何引入本地图片(引入图片地址不使用网络地址)?

react,swiper走马灯代码如下:

import React from 'react';
import { Space, Swiper } from 'antd-mobile';
import styles from './demo2.less';
const colors = ['red', 'yellow', 'blue', 'green'];
const items = colors.map((color, index) => (<Swiper.Item key={index}>
    <div className={styles.content} style={{ background: color }}>
      {index + 1}
    </div>
  </Swiper.Item>));
export default () => {
    return (
        <Space direction='vertical' block>
          <Swiper indicatorProps={{
            color: 'white',
        }} defaultIndex={0}>
            {items}
          </Swiper>
        </Space>
    );
};

该走马灯样式文件代码如下:

.content {
    height: 120px;
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 48px;
    user-select: none;
    background-image: url(../Homepage/1.JPG);
  }

  .customIndicator {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 8px;
    color: #ffffff;
    border-radius: 4px;
    user-select: none;
  }

请问在图片地址不能是网络地址如http开头的情况下,如何引入4张放置在homepage文件夹里的本地图片?

  • 写回答

2条回答 默认 最新

  • 崽崽的谷雨 2022-09-07 09:59
    关注

    Swiper.Item 里加个 img src=“xxx路径”

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月15日
  • 已采纳回答 9月7日
  • 修改了问题 9月6日
  • 创建了问题 9月6日