nativescript-vue 的 nativescript-fonticon
nativescript-fonticon for nativescript-vue
我正在尝试添加插件:nativescript-fonticon
我目前卡在必须转换 css 文件的部分。
在自述文件中,它指出我必须在开始转换之前配置我的 css 和转换器:
import * as application from 'application';
import {TNSFontIcon, fonticon} from 'nativescript-fonticon';
TNSFontIcon.debug = true; <-- Optional. Will output the css mapping to console.
TNSFontIcon.paths = {
'fa': 'font-awesome.css',
'ion': 'ionicons.css'
};
TNSFontIcon.loadCss();
application.resources['fonticon'] = fonticon;
application.start({ moduleName: 'main-page' });
我应该如何在 nativescript-vue 中执行此操作?
我找到了一个实际使用fonticons插件的博客以及如何使用它:
https://nativescript-vue.org/blog/using-fonticons/
编辑:
在几次 Nativescript 和 Nativescript-Vue 更新后,它似乎无法正常工作。比较难用。
我建议像这样导入字体并使用相应的 unicode:
数据:
icon: '\ue905'
标记:
<Label class="ico" :text="icon"/>
你看起来走对了路。您应该将初始化代码放入 main.js
文件(或任何命名的入口点文件)。
以下是如何让它在 NativeScript-Vue 中工作。
从 here 下载并提取 fontawesome-free-5.9.0-web.zip
。
将 webfonts/fa-brands-400.ttf
、webfonts/fa-regular-400.ttf
和 webfonts/fa-solid-900.ttf
添加到 app/fonts
目录。
将 css/fontawesome.css
添加到 app/assets
目录。从此文件中删除任何非 fa-*:before
classes。
在您应用的 main.js
中。启动应用程序时,您应该会看到每个 class 的控制台日志。
import { TNSFontIcon, fonticon } from 'nativescript-fonticon'
TNSFontIcon.debug = true
TNSFontIcon.paths = {
'fa': './assets/fontawesome.css',
}
TNSFontIcon.loadCss()
Vue.filter('fonticon', fonticon)
在您应用的主 css 文件中,例如app.scss
.
.fa-brands {
font-family: "Font Awesome 5 Brands", "fa-brands-400";
}
.far {
font-family: "Font Awesome 5 Free", "fa-regular-400";
font-weight: 400;
}
.fas {
font-family: "Font Awesome 5 Free", "fa-solid-900";
font-weight: 900;
}
现在在您的视图中使用它们。
<Label :text="'fa-facebook-f' | fonticon" class="fa-brands" />
<Label :text="'fa-eye' | fonticon" class="far" />
<Label :text="'fa-eye' | fonticon" class="fas" />
我正在尝试添加插件:nativescript-fonticon
我目前卡在必须转换 css 文件的部分。
在自述文件中,它指出我必须在开始转换之前配置我的 css 和转换器:
import * as application from 'application';
import {TNSFontIcon, fonticon} from 'nativescript-fonticon';
TNSFontIcon.debug = true; <-- Optional. Will output the css mapping to console.
TNSFontIcon.paths = {
'fa': 'font-awesome.css',
'ion': 'ionicons.css'
};
TNSFontIcon.loadCss();
application.resources['fonticon'] = fonticon;
application.start({ moduleName: 'main-page' });
我应该如何在 nativescript-vue 中执行此操作?
我找到了一个实际使用fonticons插件的博客以及如何使用它: https://nativescript-vue.org/blog/using-fonticons/
编辑: 在几次 Nativescript 和 Nativescript-Vue 更新后,它似乎无法正常工作。比较难用。 我建议像这样导入字体并使用相应的 unicode:
数据:
icon: '\ue905'
标记:
<Label class="ico" :text="icon"/>
你看起来走对了路。您应该将初始化代码放入 main.js
文件(或任何命名的入口点文件)。
以下是如何让它在 NativeScript-Vue 中工作。
从 here 下载并提取 fontawesome-free-5.9.0-web.zip
。
将 webfonts/fa-brands-400.ttf
、webfonts/fa-regular-400.ttf
和 webfonts/fa-solid-900.ttf
添加到 app/fonts
目录。
将 css/fontawesome.css
添加到 app/assets
目录。从此文件中删除任何非 fa-*:before
classes。
在您应用的 main.js
中。启动应用程序时,您应该会看到每个 class 的控制台日志。
import { TNSFontIcon, fonticon } from 'nativescript-fonticon'
TNSFontIcon.debug = true
TNSFontIcon.paths = {
'fa': './assets/fontawesome.css',
}
TNSFontIcon.loadCss()
Vue.filter('fonticon', fonticon)
在您应用的主 css 文件中,例如app.scss
.
.fa-brands {
font-family: "Font Awesome 5 Brands", "fa-brands-400";
}
.far {
font-family: "Font Awesome 5 Free", "fa-regular-400";
font-weight: 400;
}
.fas {
font-family: "Font Awesome 5 Free", "fa-solid-900";
font-weight: 900;
}
现在在您的视图中使用它们。
<Label :text="'fa-facebook-f' | fonticon" class="fa-brands" />
<Label :text="'fa-eye' | fonticon" class="far" />
<Label :text="'fa-eye' | fonticon" class="fas" />