use*_*128 6 font-awesome vue.js nativescript
我正在尝试使用FontAwesome图标集在NativeScript和Vue.js上构建应用程序,但由于我什至没有错误提示消息,所以无法解决问题。
我忠实地遵循文档,但没有任何反应。我到处搜寻,但是..一无所有。
如果您可以帮助我,我将非常感激。
文档:https : //nativescript-vue.org/blog/using-fonticons/
谢谢!
解
.fa { font-family: 'Font Awesome 5 Free', 'font-awesome/fa-regular-400'; }
.fas { font-family: 'Font Awesome 5 Free', 'font-awesome/fa-solid-900'; }
.fab { font-family: 'Font Awesome 5 Free', 'font-awesome/fa-brands-400'; }
Run Code Online (Sandbox Code Playgroud)
字体家族的第一部分是命名字体家族,然后以逗号开头,我们将写出这些字体的路径。
要获得NativeScript-Vue的工作品牌和Pro FontAwesome 5字体,安装nativescript-fonticon
,npm install nativescript-fonticon --save
如文档中所述使用Fonticons,并从FontAwesome同时下载网络字体和桌面字体。在目录中,从Web下载目录中app/fonts
添加.ttf
文件webfonts
。iOS版也需要.otf
从文件otfs
桌面下载的目录,以便这些添加到app/fonts
目录以及并重命名的基本部分.otf
文件,以便与相应基名.ttf
的文件
在app/assets
从添加相应的css文件css
的Web字体下载的目录(或所有文件)。
现在添加以下内容app.scss
(请注意,如果未font-weight
正确定义,则灯光和实体将无法正常工作)
.fa {
font-family: "Font Awesome 5 Pro", "fa-regular-400";
font-weight: 400;
}
.fas {
font-family: "Font Awesome 5 Pro", "fa-solid-900";
font-weight: 900;
}
.fab {
font-family: "Font Awesome 5 Brands", "fa-brands-400";
font-weight: 400;
}
.fal {
font-family: "Font Awesome 5 Pro", "fa-light-300";
font-weight: 300;
}
Run Code Online (Sandbox Code Playgroud)
和以下 main.ts
import {TNSFontIcon, fonticon} from 'nativescript-fonticon';
TNSFontIcon.debug = true;
TNSFontIcon.paths = {
// 'fa': './assets/css/all.min.css',
// 'fal': './assets/css/all.min.css',
// 'far': './assets/css/all.min.css',
// 'fas': './assets/css/all.min.css',
// 'fab': './assets/css/all.min.css',
'fa': './assets/css/fontawesome.min.css',
'fal': './assets/css/light.min.css',
'far': './assets/css/regular.min.css',
'fas': './assets/css/solid.min.css',
'fab': './assets/css/brands.min.css'
};
TNSFontIcon.loadCss();
Vue.filter('fonticon', fonticon);
Run Code Online (Sandbox Code Playgroud)
现在删除platforms
目录,以确保所有内容都正确捆绑在一起,您应该一切顺利。像这样使用
<StackLayout orientation="horizontal" horizontalAlignment="center" verticalAlignment="top">
<Label class="fab" :text="'fa-git' | fonticon" />
<Label class="fal" :text="'fa-plus-square' | fonticon" />
<Label class="fa" :text="'fa-plus-square' | fonticon" />
<Label class="fas" :text="'fa-plus-square' | fonticon" />
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
为了使事情变得更加容易,有一个插件Vue-Fonticon实质上是我复制到的以下代码app/components/FontIcon.vue
<template>
<Label
:class="type"
:color="color"
:fontSize="size"
:text="name | fonticon"
:width="size"
textAlignment="center"
@tap="$emit('tap')"
/>
</template>
<script>
export default {
name: 'FontIcon',
props: {
color: {
type: String,
default: 'black'
},
name: {
type: String,
required: true
},
size: {
type: [String, Number],
default: 15,
validation: s => !isNaN(s)
},
type: {
type: String,
default: 'fa'
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
要使用它,在main.ts
添加
import FontIcon from './components/Utility/FontIcon.vue'
Vue.component(FontIcon.name, FontIcon)
Run Code Online (Sandbox Code Playgroud)
并用作
<StackLayout orientation="horizontal" horizontalAlignment="center" verticalAlignment="top">
<FontIcon name="fa-play"/>
<FontIcon name="fa-play" type="fal"/>
<FontIcon name="fa-play" type="fas"/>
<FontIcon name="fa-git" type="fab"/>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
它对我使用 FontAwesome 4.7.0 有用。从5.0版本开始,font Awesome的封装发生了变化,使用ttf不再是推荐的方式,也许在nativescript-vue中使用font Awesome 5.x更加棘手。
您可以在那里下载: https: //fontawesome.com/v4.7.0/
按照文档中的说明使用 fontawesome-webfont.ttf 并将其重命名为 FontAwesome.ttf,也复制 font-awesome.min.css
在你的 app.scss 中,不要忘记这一点(字体系列是你的 ttf 文件的名称)
.fa {
font-family: FontAwesome;
}
Run Code Online (Sandbox Code Playgroud)
请记住检查 v4.7 上的图标名称,有些是 v5 中的新名称
在调试模式下,当您的应用程序启动时,您应该看到:
JS: 'Collections to load: fa'
JS: '----------'
JS: 'Loading collection \'fa\' from file: ./fonts/FontAwesome.css'
JS: 'fa-glass: \\uf000'
JS: 'fa-music: \\uf001'
JS: 'fa-search: \\uf002'
JS: 'fa-envelope-o: \\uf003'
...
Run Code Online (Sandbox Code Playgroud)