如何解决semantic-ui-react图像组件不显示图像的问题

发布时间:2021-10-21 09:37:55 作者:小新
来源:亿速云 阅读:122

这篇文章主要介绍了如何解决semantic-ui-react图像组件不显示图像的问题,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

问题

React提供了一种相当科学的开发Web应用前端视图层的技术,借助于semantic-ui for React可以很容易地搭建起常用网页开发中的UI组件,但是最近在分析其提供的各种组件时发现Image组件存在一个小问题,记录于此。

我最初代码形式

import React from 'react'
import {
    Grid,
    Image,
} from 'semantic-ui-react'

const ImageExampleLink = () => (
    <Grid container stackable verticalAlign='middle'>
        <Grid.Row>
            <Grid.Column  floated='left' width={4}>
                <Image
                    bordered
                    rounded
                    size='small'
                    src='./help.png'
                />
            </Grid.Column>
            <Grid.Column floated='right' width={4}>
                <Image
                    bordered
                    rounded
                    size='small'
                    src='./help.png'
                />
            </Grid.Column>
        </Grid.Row>
        <Grid.Row>
            <Grid.Column  floated='right' >
                <Image
                    size='mini'
                    avatar
                    src='./help.png'
                />
            </Grid.Column>
        </Grid.Row>
    </Grid>
)

export default ImageExampleLink

其中图像文件的路径位置没有问题,但是运行中发现图像死活不显示,只显示一个通用的系统提供的那种你常见的占位符形式。
然后,通过google浏览器搜索分析,发现了一个看似相近的题目「Semantic-UI Image properties not working with semantic-ui-react」(https://stackoverflow.com/questions/44609711/semantic-ui-image-properties-not-working-with-semantic-ui-react)。
其实,上面的问题与我的不一样,semantic-ui-react系统所使用的css文件我是的确导入了。我的有关安装及使用方式是这样的:


npm install semantic-ui-react --save
npm install semantic-ui-css

npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.

然后在index.js里导入
import 'semantic-ui-css/semantic.min.css';

上述步骤没有什么问题,因为我使用其他许多组件(我是在app.js中进行测试使用各种组件的)是没有问题的。


在上面的stackoverflow.com问题中,那位回答者的回答是“Semantic UI React requires a Semantic UI' CSS, you forgot to setup it, here is instuctions.”。我跟踪这个链接过去,只是简单地转入了官方展示网站,没有什么,我早就比较熟悉这个地方了。但是,受到此处的一点启动,我把代码中的src属性的地址形式变换了一个,使用了JSX语言推荐的如下表达形式。

改进后代码形式

import React from 'react'
import {
    Grid,
    Image,
} from 'semantic-ui-react'
import help from './help.png';

const ImageExampleLink = () => (
    <Grid container stackable verticalAlign='middle'>
        <Grid.Row>
            <Grid.Column  floated='left' width={4}>
                <Image
                    bordered
                    rounded
                    size='small'
                    src={help}
                />
            </Grid.Column>
            <Grid.Column floated='right' width={4}>
                <Image
                    bordered
                    rounded
                    size='small'
                    src={help}
                />
            </Grid.Column>
        </Grid.Row>
        <Grid.Row>
            <Grid.Column  floated='right' >
                <Image
                    size='mini'
                    avatar
                    src={help}
                />
            </Grid.Column>
        </Grid.Row>
    </Grid>
)

export default ImageExampleLink

请注意上面代码最初的import语句和改进后的Image组件的src属性值的表达方式。再试运行,OK!

感谢你能够认真阅读完这篇文章,希望小编分享的“如何解决semantic-ui-react图像组件不显示图像的问题”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. cacti不能显示图像数据故障处理办法
  2. jupyter如何使用Pillow包显示图像时inline显示

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

semantic react

上一篇:怎么建立Banner组件库

下一篇:SpringBean循环依赖问题的解决方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》