第一步
安装loader
yarn add svg-sprite-loader@4.1.3
第二步
配置vue.config.js文件
chainWebpack(config) {
// set svg-sprite-loader
config.module
.rule('svg')
.exclude.add(resolve('src/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
}
第三步
创建一个svg组件
src\components\SvgIcon\index.vue
第四步
创建icons文件夹,在index,js中注册成全局组件
src/icons/index.js
第五步
在main.js中引入icons/index.js
第六步
使用组件
例如:
<svg-icon icon-class="tree" />
<svg-icon icon-class="user" />
怎么下载svg图标
.svg是一种通过代码的方式来展示的图片格式(.png, .gif.....)