1.安装  路由模块  及  状态管理模块

  1. npm install vue-router --save
  2. npm install vuex --save

2.自定义  TabBar  组件

src / components / TabBar.vue

TabBar.vue

  1. <!-- 底部选项卡 -->
  2. <template>
  3. <div class="wrapper">
  4. <div class="bar-item" @click="tabTo('home')">
  5. <text class="bar-ic iconfont" :style="testCS"></text>
  6. <text class="bar-txt">首页</text>
  7. </div>
  8. <div class="bar-item" @click="tabTo('topic')">
  9. <text class="bar-ic iconfont"></text>
  10. <text class="bar-txt">专题</text>
  11. </div>
  12. <div class="bar-item act" @click="tabTo('class')">
  13. <text class="bar-ic iconfont"></text>
  14. <text class="bar-txt">分类</text>
  15. </div>
  16. <div class="bar-item" @click="tabTo('shop')">
  17. <text class="bar-ic iconfont"></text>
  18. <text class="bar-txt">购物车</text>
  19. </div>
  20. <div class="bar-item" @click="tabTo('my')">
  21. <text class="bar-ic iconfont"></text>
  22. <text class="bar-txt">个人</text>
  23. </div>
  24. </div>
  25. </template>
  26.  
  27. <script>
  28. var modal = weex.requireModule('modal');
  29.  
  30. export default {
  31. computed:{
  32. testCS:function () {
  33. return this.pIndexKey == 'home'?'color:#b4282d;':''
  34. }
  35. },
  36. data () {
  37. return {
  38. pIndexKey:'home'
  39. }
  40. },
  41. mounted(){
  42. },
  43. methods: {
  44. tabTo(_key){
  45. if(this.pIndexKey == _key) return;
  46. this.pIndexKey = _key;
  47. this.$emit('tabTo',{
  48. status : 'tabTo',
  49. data : {
  50. key : _key
  51. }
  52. })
  53. }
  54. }
  55. }
  56. </script>
  57.  
  58. <style scoped>
  59. .iconfont {
  60. font-family:iconfont;
  61. }
  62. .wrapper{
  63. position: fixed;
  64. bottom: 0;
  65. left: 0;right: 0;
  66. height: 90px;
  67. flex-wrap: nowrap;
  68. flex-direction: row;
  69. justify-content: space-around;
  70. border-top-width: 1px;
  71. border-top-color: #d9d9d9;
  72. background-color: #fafafa;
  73. }
  74. .bar-item{
  75. flex: 1;
  76. }
  77. .bar-txt,.bar-ic{
  78. color:#666;
  79. text-align: center;
  80. }
  81. .bar-active{
  82. color:#b4282d;
  83. }
  84. .bar-ic{
  85. padding-top: 14px;
  86. font-size: 38px;
  87. }
  88. .bar-txt{
  89. font-size: 22px;
  90. padding-top: 2px;
  91. }
  92. </style>

3.自定义  工具类

src / utils / util.js

util.js

  1. /**
  2. * 工具类
  3. */
  4.  
  5. let utilFunc = {
  6. initIconFont () {
  7. let domModule = weex.requireModule('dom');
  8. domModule.addRule('fontFace', {
  9. 'fontFamily': "iconfont",
  10. 'src': "url('http://at.alicdn.com/t/font_404010_jgmnakd1zizr529.ttf')"
  11. });
  12. },
  13. setBundleUrl(url, jsFile) {
  14. const bundleUrl = url;
  15. let host = '';
  16. let path = '';
  17. let nativeBase;
  18. const isAndroidAssets = bundleUrl.indexOf('your_current_IP') >= 0 || bundleUrl.indexOf('file://assets/') >= 0;
  19. const isiOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('WeexDemo.app') > 0;
  20. if (isAndroidAssets) {
  21. nativeBase = 'file://assets/dist';
  22. } else if (isiOSAssets) {
  23. // file:///var/mobile/Containers/Bundle/Application/{id}/WeexDemo.app/
  24. // file:///Users/{user}/Library/Developer/CoreSimulator/Devices/{id}/data/Containers/Bundle/Application/{id}/WeexDemo.app/
  25. nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1);
  26. } else {
  27. const matches = /\/\/([^\/]+?)\//.exec(bundleUrl);
  28. const matchFirstPath = /\/\/[^\/]+\/([^\s]+)\//.exec(bundleUrl);
  29. if (matches && matches.length >= 2) {
  30. host = matches[1];
  31. }
  32. if (matchFirstPath && matchFirstPath.length >= 2) {
  33. path = matchFirstPath[1];
  34. }
  35. nativeBase = 'http://' + host + '/';
  36. }
  37. const h5Base = './index.html?page=';
  38. // in Native
  39. let base = nativeBase;
  40. if (typeof navigator !== 'undefined' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko')) {
  41. // check if in weexpack project
  42. if (path === 'web' || path === 'dist') {
  43. base = h5Base + '/dist/';
  44. } else {
  45. base = h5Base + '';
  46. }
  47. } else {
  48. base = nativeBase + (!!path? path+'/':'');
  49. }
  50.  
  51. const newUrl = base + jsFile;
  52. return newUrl;
  53. },
  54. getUrlSearch(url,name) {
  55. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  56. var r = url.slice(url.indexOf('?')+1).match(reg);
  57. if (r != null) {
  58. try {
  59. return decodeURIComponent(r[2]);
  60. } catch (_e) {
  61. return null;
  62. }
  63. }
  64. return null;
  65. }
  66. };
  67.  
  68. export default utilFunc;  

4.其他页面

src / pages / Home / Home.vue

例如:Home.vue

  1. <!-- 首页 -->
  2. <template>
  3. <div>
  4. <text>首页</text>
  5. </div>
  6. </template>
  7.  
  8. <script>
  9. export default {
  10. name: 'Home',
  11. data: () => ({
  12. //
  13. }),
  14. created () {
  15. //
  16. },
  17. methods: {
  18. //
  19. }
  20. };
  21. </script>
  22.  
  23. <style scoped>
  24. </style>

5.配置 路由

src / router / index.js

index.js

  1. /**
  2. * 配置路由
  3. */
  4. import Router from 'vue-router'
  5. // 首页
  6. import Home from '../pages/Home/Home.vue'
  7. // 专题
  8. import Topic from '../pages/Topic/Topic.vue'
  9. // 分类
  10. import Class from '../pages/Class/Class.vue'
  11. // 购物车
  12. import Shop from '../pages/Shop/Shop.vue'
  13. // 个人
  14. import My from '../pages/My/My.vue'
  15.  
  16. Vue.use(Router)
  17.  
  18. export default new Router({
  19. // mode: 'abstract',
  20. routes: [
  21. { path: '/', redirect: '/home' },
  22. { path: '/home', component: Home },
  23. { path: '/topic', component: Topic },
  24. { path: '/class', component: Class },
  25. { path: '/shop', component: Shop },
  26. { path: '/my', component: My }
  27. ]
  28. })

6.主页面  引入 工具类  及  TabBar 组件

src / App.vue

App.vue

  1. <!-- 主页面 -->
  2. <template>
  3. <div class="app-wrapper">
  4. <router-view class="r-box"></router-view>
  5. <tab-bar @tabTo="onTabTo"></tab-bar>
  6. </div>
  7. </template>
  8.  
  9. <script>
  10. var modal = weex.requireModule('modal');
  11. import util from './utils/util.js';
  12. import tabBar from './components/TabBar.vue';
  13.  
  14. export default {
  15. data () {
  16. return {
  17. //
  18. }
  19. },
  20. components: {
  21. 'tab-bar': tabBar
  22. },
  23. created () {
  24. util.initIconFont();
  25. },
  26. methods: {
  27. onTabTo(_result){
  28. let _key = _result.data.key || '';
  29. this.$router && this.$router.push('/'+_key)
  30. }
  31. }
  32. }
  33. </script>
  34.  
  35. <style>
  36. body{
  37. margin: 0;
  38. padding: 0;
  39. background-color: #f4f4f4;
  40. color:#333;
  41. }
  42. </style>
  43.  
  44. <style scoped>
  45. .app-wrapper{
  46. background-color: #f4f4f4;
  47. }
  48. .r-box{
  49. position: absolute;
  50. top:0;
  51. left: 0;
  52. right: 0;
  53. bottom: 0;
  54. }
  55. </style>

7.定义  入口文件  entry.js

src / entry.js

  1. /**
  2. * 入口文件
  3. */
  4. import App from './App.vue'
  5. import router from './router'
  6.  
  7. // 创建应用程序实例
  8. new Vue(Vue.util.extend({ el: '#root', router }, App));
  9.  
  10. router.push('/');

8.在  webpack.config.js 中配置 入口文件

  1. /***************** 配置入口文件 start *****************/
  2. const entry = {index: pathTo.resolve('src', 'entry.js')};
  3. const weexEntry = {index: pathTo.resolve('src', 'entry.js')};
  4. /****************** 配置入口文件 end ******************/

9.项目 结构

10.效果图

注:#root 报错

如果你使用的是 entry.js 作为入口文件,就需要删除 webpack.conf.js 文件中的 getEntryFileContent 和 walk 方法。

weex 项目开发(四)项目框架搭建 及 自定义 TabBar 组件的更多相关文章

  1. Django (九) 项目开发流程&项目架构

    项目开发流程&项目架构 1. 软件开发的一般流程 1. 需求分析及确认: 由需求分析工程师与客户确认甚至挖掘需求.输出需求说明文档. ​ 2. 概要设计及详细设计: 开发对需求进行概要设计,包 ...

  2. AngularJS进阶(三十一)AngularJS项目开发技巧之获取模态对话框中的组件ID

    AngularJS项目开发技巧之获取模态对话框中的组件ID 需求 出于项目开发需求,需要实现的业务逻辑是:药店端点击查看"已发货""已收货"订单详情时,模块弹出 ...

  3. cocos2dx之lua项目开发中MVC框架的简单应用

    **************************************************************************** 时间:2015-03-31 作者:Sharin ...

  4. 01-电子商城项目介绍及ssm框架搭建

    1.B2C电商项目功能及架构 1.1功能列表 1.2系统架构(soa架构) 2.后台管理系统工程搭建及测试 ypMall,ypMall-manager-web ypMall为父项目,管理子项目的jar ...

  5. Vue/Egg大型项目开发(一)搭建项目

    项目Github地址:前端(https://github.com/14glwu/stuer)后端(https://github.com/14glwu/stuer-server) 项目线上预览:http ...

  6. weex 项目开发 weexpack 项目 打包、签名、发布

    一. weexpack build android  和  weexpack run android 的 区别. (1)单纯打包 weexpack build android (2)打包并运行 wee ...

  7. Android项目开发四

    微博客户端开发 本周学习计划 研究微博客户端关于Sqlite数据库代码. 完成微博撰写.发布等功能模块. 将程序中存在的问题解决. 实际完成情况 Sqlite数据库学习与研究 微博客户端功能设定中涉及 ...

  8. [SSM项目]二-项目设计和框架搭建

    一 10个实体类 选择Integer 而不是int的原因 :当值为空时,int类型会自动为其初始化,这是我们不希望的. 二 配置Maven 目录结构: src/main/java:业务代码 src/m ...

  9. JAVA项目从运维部署到项目开发(四. Tomcat)

    一.关于中文乱码问题 文件目录:/conf/server.xml 将相关语句改为: <Connector port="8008" protocol="HTTP/1. ...

随机推荐

  1. python 基础知识汇总—— if else while continue

    1.if 语句 什么是if语句?if语句用来干什么的? if语句说通俗点,就是判断,如果判断条件为真,那么就执行语句,就像我们生活中例子,如果你饿了,判断为真,就要吃饭,于是你就会执行吃饭这个动作,如 ...

  2. 剑指Offer(书):反转链表

    题目:输入一个链表,反转链表后,输出新链表的表头. 分析:要分清他的前一个节点和后一个节点,开始的时候前节点为null,后节点为head.next,之后,反转. public ListNode Rev ...

  3. 自定义iOS上双击Home键图切换

    如果双击Home,会来到iOS App的switcher页面,在这儿列出了当前系统挂起的App, 上面有每个App的切屏,相信大家都熟悉这个东东了.它其实是每个App在挂起前,对App后个载屏. 那么 ...

  4. undertow的PUT参数获取问题

    今天使用undertow遇到一个问题,记录一下: 首先,maven配置如下: <dependency> <groupId>org.springframework.boot< ...

  5. 使用systemctl命令管理服务mysql

    启动mysql systemctl start mysqld.service 停止mysql systemctl stop mysqld.service 重启mysql systemctl resta ...

  6. IntelliJ IDEA 代码提示快捷键

    1.写代码时用Alt-Insert(Code|Generate…)可以创建类里面任何字段的getter与setter方法. mac版 是ctrl+enter 2.CodeCompletion(代码完成 ...

  7. SPOJ NSUBSTR Substrings ——后缀自动机

    建后缀自动机 然后统计次数,只需要算出right集合的大小即可, 然后更新f[l[i]]和rit[i]取个max 然后根据rit集合短的一定包含长的的性质,从后往前更新一遍即可 #include &l ...

  8. BZOJ 1072 [SCOI2007]排列perm ——状压DP

    [题目分析] 没什么好说的,水题. 代码比较丑,结果需要开long long 时间爆炸 [代码] #include <cstdio> #include <cstring> #i ...

  9. 济南学习 Day 5 T3 am

    [题目描述] 众所不知,rly现在不会玩国际象棋.但是,作为一个OIer,rly当然做过八皇后问题.在这里再啰嗦几句,皇后可以攻击到同行同列同对角线,在 n*n的棋盘中,摆放n个皇后使它们互相不能攻击 ...

  10. Wannafly挑战赛11 D 题 字符串hash + 卡常

    题目链接 https://ac.nowcoder.com/acm/contest/73#question map与order_map https://blog.csdn.net/BillCYJ/art ...