UNI-APP添加顶部导航栏并且更换图标
uni-app
是一个使用 Vue.js 开发跨平台应用的前端框架。
开发者通过编写 Vue.js 代码,uni-app 将其编译到iOS、Android、微信小程序等多个平台,保证其正确运行并达到优秀体验。
记录一下更换顶部导航栏的流程
![](https://upload-images.jianshu.io/upload_images/5095440-d1d97eab4ca6b656.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/590/format/webp)
最终效果图
在page.json里的配置项
{
"path": "pages/my/index",
"style": {
"app-plus": {
"titleNView": {
"buttons": [{
"text": "ue605",
"fontSrc": "/static/iconfont.ttf",
"fontSize": "22px",
"float": "left"
},
{
"text": "ue606",
"fontSrc": "/static/iconfont.ttf",
"fontSize": "22px"
}
]
}
}
}
},
更换图标
1.在阿里巴巴矢量图选择自己喜欢的图标,然后点击收藏
![](https://upload-images.jianshu.io/upload_images/5095440-3223d6557855c32c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
收藏图标
2.右上角下载全部已经收藏了的图标
![](https://upload-images.jianshu.io/upload_images/5095440-952baa932a773f79.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/304/format/webp)
下载
3.在编辑器打开已经下载的文件,把文件里的iconfont.ttf丢到static文件夹里,然后再打开iconfont.css里查看unicode编码
![](https://upload-images.jianshu.io/upload_images/5095440-796c424a813a2297.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/805/format/webp)
unicode编码
4.最后把对应图标的编码填写到page.json的配置项里text,需要写成一个"u***",然后重启就实现了
5.最后在对应的页面生命周期方法里填写,通过e.index,来配置不同的方法
onNavigationBarButtonTap:function(e){
console.log(JSON.stringify(e))
},