Repository navigation
Vue配置svg-sprite-loader以使用svg图标 #2
Description
Activity
- changed the title
[-]vue配置svg-sprite-loader以使用svg图标[/-][+]Vue配置svg-sprite-loader以使用svg图标[/+]on Jan 1, 2018 手把手教學 寫的非常好!!!!新手入門配置好久終於找到能用的了
只是不知道是不是我之前遺留的問題 須將iconName() { return '#' + this.$props.type }改成iconName() { return '#icon-' + this.$props.type }@kururu002 本文基本写明了每一步步骤,命名什么的可能要看怎么使用的。如果您喜欢这篇文章,欢迎给这个仓库star,权当鼓励。(哈哈)
以下是我用svg-sprite-loader 插件生成的图片,怎么把<title>avatar</title>删掉呢? 有相关配置选项么?
<title>avatar</title>
@yuying-kooboo 没能理解你说的意思,可以看下原文件和生成的文件的内容?
@yuying-kooboo 可以看下 svg 源文件的内容吗?这个应该是你的 svg 源文件内容里就有的 title ,你可以修改源文件试下。
@yuying-kooboo 用编辑器 打开你的 svg 源文件,svg文件是可以修改的,结构类似 HTML
Hi, svg源文件是可以修改的,谢谢你了~
@yuying-kooboo :)
4 remaining items
@brantcao 你可以发一份你的代码(简化后的)给我,我看一下,因为这样在 git issues 里聊的话太费劲了。邮箱:[email protected]
- 你好, 可以的,我本来都是demo。太感谢你了。 firstVue.zip <https://drive.google.com/file/d/1LaDce5ttOqPQB-V23dIGFfU-qS6K_Pae/view?usp=drive_web> 夜行 <[email protected]> 于2019年5月22日周三 上午11:30写道:…@brantcao <https://github.com/brantcao> 你可以发一份你的代码(简化后的)给我们,我看一下,因为这样在 git issues ***@***.*** — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGQBX53QHIK4CTEB7KEDJ7TPWS44PANCNFSM4EJ75A2A> .
@brantcao 你的 webpack.base.conf.js 配置有问题,
url-loader的配置覆盖了svg-sprite-loader的配置,注释掉上面 这个url-loader中的svg就可以了。- 你好,太感谢你了,我研究这个问题,两天了,因为我自己没注意细节,一直没有解决这个问题。真的非常感谢你。请问以后假如有其他问题,可以通过什么方式给你留言呢? 再次表示感谢。 夜行 <[email protected]> 于2019年5月22日周三 下午2:58写道:…@brantcao <https://github.com/brantcao> 你的 webpack.base.conf.js 配置有问题, url-loader 的配置覆盖了 svg-sprite-loader 的配置,注释掉上面 这个 url-loader 中的 svg 就可以了。 [image: image] <https://user-images.githubusercontent.com/26452939/58153280-36a6f100-7ca1-11e9-9973-4646870f74d1.png> [image: image] <https://user-images.githubusercontent.com/26452939/58153171-019a9e80-7ca1-11e9-9b05-8fb8f443f720.png> — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGQBX53GM4KESYAS4W3RHRLPWTVI7ANCNFSM4EJ75A2A> .
@brantcao 邮箱:[email protected] 。如果可以的话,麻烦帮我点个 star,谢谢。:)
- 你每次都好认真的回答每个人啊,点赞,去给你点了一个star…------------------ 原始邮件 ------------------ 发件人: "夜行"<[email protected]>; 发送时间: 2019年5月22日(星期三) 下午3:20 收件人: "justemit/coding-note"<[email protected]>; 抄送: "心语"<[email protected]>; "Mention"<[email protected]>; 主题: Re: [justemit/coding-note] Vue配置svg-sprite-loader以使用svg图标 (#2) @brantcao 邮箱:[email protected] 微信:kaivn07 。如果可以的话,麻烦帮我点个 star,谢谢。:) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
- 是的,太认真了,解决了我两天的难题。 yuying-kooboo <[email protected]> 于2019年5月22日周三 下午3:22写道:…你每次都好认真的回答每个人啊,点赞,去给你点了一个star ------------------ 原始邮件 ------------------ 发件人: ***@***.***>; 发送时间: 2019年5月22日(星期三) 下午3:20 收件人: ***@***.***>; 抄送: ***@***.***>; ***@***.***>; 主题: Re: [justemit/coding-note] Vue配置svg-sprite-loader以使用svg图标 (#2) @brantcao ***@***.*** 微信:kaivn07 。如果可以的话,麻烦帮我点个 star,谢谢。:) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGQBX555JK7UOCZMJULUUODPWTYD5ANCNFSM4EJ75A2A> .
哈哈,谢谢你们
有没有办吧修改svg组件的颜色呢color ,我添加css {fill:red} 这样貌似无效
- Hi 目前,我遇到一个困难,你看你们能有办法吗? 我们项目是一套代码,然后,26个网址都在调用,然后,每个站有自己独特的,然后,也有公用的都写到common目录里面。 我开始 svg-sprite-loader 使用这个的时候,直接都放到common里面的,多站都可以一起调用。但是,现在新的需求,有一些icon svg 只有 am项目用,其他都用不到,假如,放到common里面的话,这样都很多冗余的了。 不知道,有没有最理想的办法就是,能使用公用的 svg icon,同时,也把自己独特目录下的 svg 也假如进去。 项目,大概结构: 截图: http://h.pz.com/u/7842/56/5/156825591526.png http://h.pz.com/u/7842/56/5/156825591511.png thanks 夜行 <[email protected]> 于2019年5月22日周三 下午3:20写道:…@brantcao <https://github.com/brantcao> ***@***.*** 微信:kaivn07 。如果可以的话,麻烦帮我点个 star,谢谢。:) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGQBX5ZCR5ADDSJX2UTXCUDPWTX5TANCNFSM4EJ75A2A> .
@brantcao 这个你得自己考虑。我的思路:不同站点分开打包,不同站点打包的 webpack 脚本大部分可以共用,然后在针对不同站点代码补充不同的 webpack 配置,可以看一下 webpack-merge 的文档。
- 谢谢你的思路,感谢。 Justemit <[email protected]> 于2019年9月15日周日 上午11:37写道:…@brantcao <https://github.com/brantcao> 这个你得自己考虑。我的思路:不同站点分开打包,不同站点打包的 webpack 脚本大部分可以共用,然后在针对不同站点代码补充不同的 webpack 配置,可以看一下 webpack-merge <https://github.com/survivejs/webpack-merge> 的文档。 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGQBX53L6LFIIEJBACCKGHTQJWUYHANCNFSM4EJ75A2A> .
您好,我也是按上面的配置做的,我的conf文件里面没有使用url-loader, svg除了用svg-sprite-loader处理之外,没有在其他的loader中处理了,但是使用的时候也是空白,0x0,能帮忙看看怎么回事吗
- Hi Zhxuc/Coding-Note 你可以加我qq 1149599859 ,然后,我帮你看看么。…On Thu, May 28, 2020 at 3:01 PM wukaMM ***@***.***> wrote: 您好,我也是按上面的配置做的,我的conf文件里面没有使用url-loader, svg除了用svg-sprite-loader处理之外,没有在其他的loader中处理了,但是使用的时候也是空白,0x0,能帮忙看看怎么回事吗 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AGQBX54CNV4UXOY5HJG7DXTRTYD5DANCNFSM4EJ75A2A> .




svg-sprite-loader在vue中的使用何为
svg sprite类似于CSS中的雪碧图。将svg整合在一起,呈现的时候根据
symbolId来显示特定的图标。svg sprite与symbol元素可以这样简单理解,
symbol是一个个svg图标,而svg sprite则是symbol的集合,我们可以通过use来指定使用哪一个svg。在
vue中使用安装
svg-sprite-loader执行
npm install --save-dev svg-sprite-loader修改
webpack.base.conf.js在rules下添加并修改以下配置:
配置说明:
svg-sprite-loader:
这里用
include: [resolve('src/icons')]来假设项目中所用到svg图标文件在src/icons文件目录下,svg-sprite-loader将只处理这里的文件url-loader:
这里用
xclude: [resolve('src/icons')]来告诉url-loader不要处理src/icons下的图片文件(因为这里已经交给svg-sprite-loader了)icon组件在
src/components文件夹下新建文件夹icon,并新建index.vue文件,写入内容如下:src/icons文件夹假如所有的
svg文件都放在src/icons/svg文件夹下,那么新建src/icons/index.js文件,写入:至此,如有不理解,可参照我的
src目录结构示意:main.js引入src/icons/index.js以我的
App.vue文件举个例子: