uniquejava / blog

My notes regarding the vibrating frontend :boom and the plain old java :rofl.
Creative Commons Zero v1.0 Universal
11 stars 5 forks source link

vue svg all in one #269

Open uniquejava opened 5 years ago

uniquejava commented 5 years ago

原理: https://www.zhangxinxu.com/wordpress/2014/07/introduce-svg-sprite-technology/ 插件: https://github.com/swisnl/vue-cli-plugin-svg-sprite

一键安装

vue add svg-sprite

这个命令 会修改如下文件:

image

详见: https://github.com/swisnl/vue-cli-plugin-svg-sprite

uniquejava commented 5 years ago

全局注册component

main.js

import SvgIcon from '@/components/SvgIcon'
Vue.component('svg-icon', SvgIcon)

svg 使用

<svg-icon :name="getIconName(req.cat)" class="large" />

jpeg

<a-avatar size="small" :src="require('@/assets/boy.jpeg')" />

change svg color

You can't change the color of an image that way. If you load SVG as an image, you can't change how it is displayed using CSS or Javascript in the browser.

If you want to change your SVG image, you have to load it using ,