_element-plus 的img怎么拿到svg图片">
赞
踩
推荐阿里巴巴图标库
命令行运行npm install svg-sprite-loader
文件内容:
<template> <svg :class="svgClass" aria-hidden="true"> <use :xlink:href="iconName"></use> </svg> </template> <script> import '@/icons' export default { name: 'svg-icon', props: { iconClass: { type: String, required: true }, className: { type: String } }, computed: { iconName() { return `#icon-${this.iconClass}` }, svgClass() { if (this.className) { console.log('svg-icon ' + this.className) return 'svg-icon ' + this.className } else { return 'svg-icon' } } }, mounted: function() { } } </script> <style scoped> .svg-icon { width: 1em; height: 1em; vertical-align: -0.15em; fill: currentColor; overflow: hidden; } </style>
文件内容如下:
import Vue from 'vue'
import svgiconfont from '@/components/svgiconfont'// svg组件
/*
require.context有三个参数:
directory:说明需要检索的目录
useSubdirectories:是否检索子目录
regExp: 匹配文件的正则表达式
*/
// 全局注册
Vue.component('svg-icon', svgiconfont)
const requireAll = requireContext => requireContext.keys().map(requireContext)
const req = require.context('./svg', false, /\.svg$/)
requireAll(req)
即添加import ‘@/icons’
添加代码:
{ test: /\.svg$/, loader: "svg-sprite-loader", include: [resolve("src/icons")], options: { symbolId: "icon-[name]" } }, { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', exclude: [resolve("src/icons")], options: { limit: 50000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } }
在页面中添加
<svg-icon icon-class="breadcrumb"></svg-icon>
如有错误的地方,请留言多多指教
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。