开始之前,开发者需先下载安装如下工具:HBuilderX:官方IDE下载地址
1、创建第一个 uni-app项目
在点击工具栏里的文件->新建->项目:
选择左边uni-app项目,输入项目名称,如:test,选址文件路径,使用默认模板,点击创建,即可成功创建一个uni-app项目。
2、项目目录介绍
新建uni-app项目成功后,项目目录生成如下图文件:
3、调试预览
新建uni-app项目成功后,即可通过点击HBuilderX工具右边预览按钮在工具内预览,可以通过预览工具栏调试查看布局结构、样式、console等
4、原生tabbar的创建和配置
打开pages.json文件,修改标题、增加页面路由、增加tabBar, tabBar增加四个“首页”,“分类”,“购物车”,“我的”。分别对应在pages目录中创建四个页面。代码如下:
{ "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages { "path": "pages/index/index", "style": { "navigationBarTitleText": "ShopWind多商户商城" } }, { "path": "pages/user/index", "style": { "navigationBarTitleText": "我的" } }, { "path": "pages/cart/index", "style": { "navigationBarTitleText": "购物车" } }, { "path": "pages/category/index", "style": { "navigationBarTitleText": "商品分类" } } ], "globalStyle": { "navigationBarTextStyle": "black", "navigationBarTitleText": "uni-app", "navigationBarBackgroundColor": "#F8F8F8", "backgroundColor": "#F8F8F8" }, "tabBar": { "color": "#333333", "selectedColor": "#fc2b34", "borderStyle": "white", "backgroundColor": "#FFFFFF", "position": "bottom", "list": [{ "pagePath": "pages/index/index", "iconPath": "static/images/home.png", "selectedIconPath": "static/images/home-hover.png", "text": "首页" }, { "pagePath": "pages/category/index", "iconPath": "static/images/gcategory.png", "selectedIconPath": "static/images/gcategory-hover.png", "text": "分类" }, { "pagePath": "pages/cart/index", "iconPath": "static/images/cart.png", "selectedIconPath": "static/images/cart-hover.png", "text": "购物车" }, { "pagePath": "pages/user/index", "iconPath": "static/images/my.png", "selectedIconPath": "static/images/my-hover.png", "text": "我的" } ] } }
5、导入静态资源包(图片)
上面代码块应用到静态资源图片,需要把图片放到static目录中
6、测试项目建好,效果如下
资源包下载
以上就是uni-app入门:项目创建及原生tabbar配置的详细内容,更多请关注php中文网其它相关文章!