vue 使用require()--拼接本地图片


1,根据类型拼接对应的图片

 

<div>
//注意:我这里是循环的取得对应的i下的type,和我下面data定义的type是相等的 <img :src="imageUrl(i.resImage)" width="84px" height="82px" alt="暂无图 片" /> </div>

2.js

 imageUrl(type) {
            let iconStr = '';
            this.typeImage.forEach(item => {
                if (item.type === type) {//根据Type拼接对应的图片
                    iconStr = require(`../resources-list/images/${item.image}`);
                } else {
                    return false;
                }
            });
            // 如果没有图片的时候给默认图片
            // if (iconStr == '') {
            //     iconStr = require('./images/nodata.png');
            // }
            return iconStr;
        },

3.data

        typeImage: [
                { type: 'kubernetes', image: 'kubernetes.png' },
                { type: 'hadoop', image: 'hadoop.png' },
                { type: 'gbase', image: 'gbase.png' },
                { type: 'gaussdb', image: 'gaussdb.png' },
                { type: 'vertica', image: 'vertica.png' },
                { type: 'teradata', image: 'teradata.png' },
                { type: 'db2', image: 'db2.png' },
                { type: 'mysql', image: 'mysql.png' },
                { type: 'oracle', image: 'oracle.png' },
                { type: 'flink', image: 'flink.png' },
                { type: 'nodata', image: 'nodata.png' },
                { type: 'hive', image: 'hive.png' },
                { type: 'spark', image: 'spark.png' },
                { type: 'hbase', image: 'hbase.png' },
                { type: 'kafka', image: 'kafka.png' },
                { type: 'redis', image: 'redis.png' },
                { type: 'elasticsearch', image: 'elasticsearch.png' },
                { type: 'codis', image: 'codis.png' },
                { type: 'ftp', image: 'ftp.png' },
                { type: 'http', image: 'http.png' },
                { type: 'mq', image: 'mq.png' },
                { type: 'minio', image: 'minio.png' },
                { type: 'postgresql', image: 'postgresql.png' },
                { type: 'postgresxl', image: 'postgresxl.png' },
                { type: 'greenplum', image: 'greenplum.png' },
                { type: 'aster', image: 'aster.png' }

            ],

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM