-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nvue中使用自定义icon; #592
Open
cps8
wants to merge
4
commits into
ijry:3.x
Choose a base branch
from
cps8:3.x
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
nvue中使用自定义icon; #592
+13
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
使用方式(这里是以本地icon为例): 1. 在图标库(如阿里矢量图库)定义好自己的项目, 在项目设置中设置好'FontClass/Symbol 前缀'和'Font Family', 比如‘FontClass/Symbol 前缀’='my-ico-', 'Font Family'='ciconfont', 字体格式勾选ttf 2. 代码中使用: 2.1. 导入字体文件, 定义UnicodeMap文件并导入, 注意: UnicodeMap的key为第1步中的FontClass/Symbol 前缀 + 图标文件的Font Class / Symbol, value是图标文件的Unicode值且以'\u'开头, 比如'my-ico-bulb-outline'='\ue6b5' import usFontUrl from '@/assets/my-icon-ciconfont/iconfont.ttf'; import usIcons from '@/assets/my-icon-ciconfont/iconUnicodeMap'; 2.2. 在data中定义返回字段 export default { data() { return { customFontUrl: usFontUrl, customIcons: usIcons } } } 2.3. 在icon组件中使用, customPrefix为第1步中设置的FontClass/Symbol 前缀不含最后的短横线, customFontFamily为第1步中设置的Font Family, name是2.1定义的UnicodeMap中的key不包含FontClass/Symbol 前缀部分 <up-icon name="bulb-outline" size="36" customPrefix="my-icon" customFontFamily="ciconfont" :customFontUrl="customFontUrl" :customIcons="customIcons"></up-icon> 2.4. 定义一个class, 使用自定义icon, class名为customPrefix的值, 为了方便全局使用,可在App.vue中定义 .us-icon { font-family: my-icon-ciconfont; text-decoration: none; text-align: center; }
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
说明 我的项目仅在Android APP中有测试过 |
代码被格式化看不出来变动哪里了 |
beforeCreate() {
// #ifdef APP-NVUE
if (this.customFontFamily) {
domModule.addRule('fontFace', {
'fontFamily': `${this.customPrefix}-${this.customFontFamily}`,
'src': `url('${this.customFontUrl}')`
})
}
// #endif
},
// 通过图标名,查找对应的图标
icon() {
// 使用自定义图标的时候页面上会把name属性也展示出来,所以在这里处理一下
if (this.customPrefix !== "uicon") {
return this.customIcons[this.customPrefix+'-'+this.name] || this.name;
}
// 如果内置的图标中找不到对应的图标,就直接返回name值,因为用户可能传入的是unicode代码
return icons['uicon-' + this.name] || this.name
} |
使用方式(这里是以本地icon为例): 1. 在图标库(如阿里矢量图库)定义好自己的项目, 在项目设置中设置好'FontClass/Symbol 前缀'和'Font Family', 比如‘FontClass/Symbol 前缀’='my-ico-', 'Font Family'='ciconfont', 字体格式勾选ttf 2. 代码中使用: 2.1. 导入字体文件, 定义UnicodeMap文件并导入, 注意: UnicodeMap的key为第1步中的FontClass/Symbol 前缀 + 图标文件的Font Class / Symbol, value是图标文件的Unicode值且以'\u'开头, 比如'my-ico-bulb-outline'='\ue6b5' import usFontUrl from '@/assets/my-icon-ciconfont/iconfont.ttf'; import usIcons from '@/assets/my-icon-ciconfont/iconUnicodeMap'; 2.2. 在data中定义返回字段 export default { data() { return { customFontUrl: usFontUrl, customIcons: usIcons } } } 2.3. 在icon组件中使用, customPrefix为第1步中设置的FontClass/Symbol 前缀不含最后的短横线, customFontFamily为第1步中设置的Font Family, name是2.1定义的UnicodeMap中的key不包含FontClass/Symbol 前缀部分 <up-icon name="bulb-outline" size="36" customPrefix="my-icon" customFontFamily="ciconfont" :customFontUrl="customFontUrl" :customIcons="customIcons"></up-icon> 2.4. 定义一个class, 使用自定义icon, class名为customPrefix的值, 为了方便全局使用,可在App.vue中定义 .us-icon { font-family: my-icon-ciconfont; text-decoration: none; text-align: center; }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
使用方式(这里是以本地icon为例):
2.1. 导入字体文件, 定义UnicodeMap文件并导入, 注意: UnicodeMap的key为第1步中的FontClass/Symbol 前缀 + 图标文件的Font Class / Symbol, value是图标文件的Unicode值且以'\u'开头, 比如'my-ico-bulb-outline'='\ue6b5'
2.2. 在data中定义返回字段
2.3. 在icon组件中使用, customPrefix为第1步中设置的FontClass/Symbol 前缀不含最后的短横线, customFontFamily为第1步中设置的Font Family, name是2.1定义的UnicodeMap中的key不包含FontClass/Symbol 前缀部分
2.4. 定义一个class, 使用自定义icon, class名为customPrefix的值, 为了方便全局使用,可在App.vue中定义