weex 项目开发(四)项目框架搭建 及 自定义 TabBar 组件
1.安装 路由模块 及 状态管理模块
npm install vue-router --save
npm install vuex --save
2.自定义 TabBar 组件
src / components / TabBar.vue
TabBar.vue
<!-- 底部选项卡 -->
<template>
<div class="wrapper">
<div class="bar-item" @click="tabTo('home')">
<text class="bar-ic iconfont" :style="testCS"></text>
<text class="bar-txt">首页</text>
</div>
<div class="bar-item" @click="tabTo('topic')">
<text class="bar-ic iconfont"></text>
<text class="bar-txt">专题</text>
</div>
<div class="bar-item act" @click="tabTo('class')">
<text class="bar-ic iconfont"></text>
<text class="bar-txt">分类</text>
</div>
<div class="bar-item" @click="tabTo('shop')">
<text class="bar-ic iconfont"></text>
<text class="bar-txt">购物车</text>
</div>
<div class="bar-item" @click="tabTo('my')">
<text class="bar-ic iconfont"></text>
<text class="bar-txt">个人</text>
</div>
</div>
</template> <script>
var modal = weex.requireModule('modal'); export default {
computed:{
testCS:function () {
return this.pIndexKey == 'home'?'color:#b4282d;':''
}
},
data () {
return {
pIndexKey:'home'
}
},
mounted(){
},
methods: {
tabTo(_key){
if(this.pIndexKey == _key) return;
this.pIndexKey = _key;
this.$emit('tabTo',{
status : 'tabTo',
data : {
key : _key
}
})
}
}
}
</script> <style scoped>
.iconfont {
font-family:iconfont;
}
.wrapper{
position: fixed;
bottom: 0;
left: 0;right: 0;
height: 90px;
flex-wrap: nowrap;
flex-direction: row;
justify-content: space-around;
border-top-width: 1px;
border-top-color: #d9d9d9;
background-color: #fafafa;
}
.bar-item{
flex: 1;
}
.bar-txt,.bar-ic{
color:#666;
text-align: center;
}
.bar-active{
color:#b4282d;
}
.bar-ic{
padding-top: 14px;
font-size: 38px;
}
.bar-txt{
font-size: 22px;
padding-top: 2px;
}
</style>
3.自定义 工具类
src / utils / util.js
util.js
/**
* 工具类
*/ let utilFunc = {
initIconFont () {
let domModule = weex.requireModule('dom');
domModule.addRule('fontFace', {
'fontFamily': "iconfont",
'src': "url('http://at.alicdn.com/t/font_404010_jgmnakd1zizr529.ttf')"
});
},
setBundleUrl(url, jsFile) {
const bundleUrl = url;
let host = '';
let path = '';
let nativeBase;
const isAndroidAssets = bundleUrl.indexOf('your_current_IP') >= 0 || bundleUrl.indexOf('file://assets/') >= 0;
const isiOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('WeexDemo.app') > 0;
if (isAndroidAssets) {
nativeBase = 'file://assets/dist';
} else if (isiOSAssets) {
// file:///var/mobile/Containers/Bundle/Application/{id}/WeexDemo.app/
// file:///Users/{user}/Library/Developer/CoreSimulator/Devices/{id}/data/Containers/Bundle/Application/{id}/WeexDemo.app/
nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1);
} else {
const matches = /\/\/([^\/]+?)\//.exec(bundleUrl);
const matchFirstPath = /\/\/[^\/]+\/([^\s]+)\//.exec(bundleUrl);
if (matches && matches.length >= 2) {
host = matches[1];
}
if (matchFirstPath && matchFirstPath.length >= 2) {
path = matchFirstPath[1];
}
nativeBase = 'http://' + host + '/';
}
const h5Base = './index.html?page=';
// in Native
let base = nativeBase;
if (typeof navigator !== 'undefined' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko')) {
// check if in weexpack project
if (path === 'web' || path === 'dist') {
base = h5Base + '/dist/';
} else {
base = h5Base + '';
}
} else {
base = nativeBase + (!!path? path+'/':'');
} const newUrl = base + jsFile;
return newUrl;
},
getUrlSearch(url,name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = url.slice(url.indexOf('?')+1).match(reg);
if (r != null) {
try {
return decodeURIComponent(r[2]);
} catch (_e) {
return null;
}
}
return null;
}
}; export default utilFunc;
4.其他页面
src / pages / Home / Home.vue
例如:Home.vue
<!-- 首页 -->
<template>
<div>
<text>首页</text>
</div>
</template> <script>
export default {
name: 'Home',
data: () => ({
//
}),
created () {
//
},
methods: {
//
}
};
</script> <style scoped>
</style>
5.配置 路由
src / router / index.js
index.js
/**
* 配置路由
*/
import Router from 'vue-router'
// 首页
import Home from '../pages/Home/Home.vue'
// 专题
import Topic from '../pages/Topic/Topic.vue'
// 分类
import Class from '../pages/Class/Class.vue'
// 购物车
import Shop from '../pages/Shop/Shop.vue'
// 个人
import My from '../pages/My/My.vue' Vue.use(Router) export default new Router({
// mode: 'abstract',
routes: [
{ path: '/', redirect: '/home' },
{ path: '/home', component: Home },
{ path: '/topic', component: Topic },
{ path: '/class', component: Class },
{ path: '/shop', component: Shop },
{ path: '/my', component: My }
]
})
6.主页面 引入 工具类 及 TabBar 组件
src / App.vue
App.vue
<!-- 主页面 -->
<template>
<div class="app-wrapper">
<router-view class="r-box"></router-view>
<tab-bar @tabTo="onTabTo"></tab-bar>
</div>
</template> <script>
var modal = weex.requireModule('modal');
import util from './utils/util.js';
import tabBar from './components/TabBar.vue'; export default {
data () {
return {
//
}
},
components: {
'tab-bar': tabBar
},
created () {
util.initIconFont();
},
methods: {
onTabTo(_result){
let _key = _result.data.key || '';
this.$router && this.$router.push('/'+_key)
}
}
}
</script> <style>
body{
margin: 0;
padding: 0;
background-color: #f4f4f4;
color:#333;
}
</style> <style scoped>
.app-wrapper{
background-color: #f4f4f4;
}
.r-box{
position: absolute;
top:0;
left: 0;
right: 0;
bottom: 0;
}
</style>
7.定义 入口文件 entry.js
src / entry.js
/**
* 入口文件
*/
import App from './App.vue'
import router from './router' // 创建应用程序实例
new Vue(Vue.util.extend({ el: '#root', router }, App)); router.push('/');
8.在 webpack.config.js 中配置 入口文件
/***************** 配置入口文件 start *****************/
const entry = {index: pathTo.resolve('src', 'entry.js')};
const weexEntry = {index: pathTo.resolve('src', 'entry.js')};
/****************** 配置入口文件 end ******************/

9.项目 结构

10.效果图

注:#root 报错
如果你使用的是 entry.js 作为入口文件,就需要删除 webpack.conf.js 文件中的 getEntryFileContent 和 walk 方法。
weex 项目开发(四)项目框架搭建 及 自定义 TabBar 组件的更多相关文章
- Django (九) 项目开发流程&项目架构
项目开发流程&项目架构 1. 软件开发的一般流程 1. 需求分析及确认: 由需求分析工程师与客户确认甚至挖掘需求.输出需求说明文档. 2. 概要设计及详细设计: 开发对需求进行概要设计,包 ...
- AngularJS进阶(三十一)AngularJS项目开发技巧之获取模态对话框中的组件ID
AngularJS项目开发技巧之获取模态对话框中的组件ID 需求 出于项目开发需求,需要实现的业务逻辑是:药店端点击查看"已发货""已收货"订单详情时,模块弹出 ...
- cocos2dx之lua项目开发中MVC框架的简单应用
**************************************************************************** 时间:2015-03-31 作者:Sharin ...
- 01-电子商城项目介绍及ssm框架搭建
1.B2C电商项目功能及架构 1.1功能列表 1.2系统架构(soa架构) 2.后台管理系统工程搭建及测试 ypMall,ypMall-manager-web ypMall为父项目,管理子项目的jar ...
- Vue/Egg大型项目开发(一)搭建项目
项目Github地址:前端(https://github.com/14glwu/stuer)后端(https://github.com/14glwu/stuer-server) 项目线上预览:http ...
- weex 项目开发 weexpack 项目 打包、签名、发布
一. weexpack build android 和 weexpack run android 的 区别. (1)单纯打包 weexpack build android (2)打包并运行 wee ...
- Android项目开发四
微博客户端开发 本周学习计划 研究微博客户端关于Sqlite数据库代码. 完成微博撰写.发布等功能模块. 将程序中存在的问题解决. 实际完成情况 Sqlite数据库学习与研究 微博客户端功能设定中涉及 ...
- [SSM项目]二-项目设计和框架搭建
一 10个实体类 选择Integer 而不是int的原因 :当值为空时,int类型会自动为其初始化,这是我们不希望的. 二 配置Maven 目录结构: src/main/java:业务代码 src/m ...
- JAVA项目从运维部署到项目开发(四. Tomcat)
一.关于中文乱码问题 文件目录:/conf/server.xml 将相关语句改为: <Connector port="8008" protocol="HTTP/1. ...
随机推荐
- Linux中断底半部机制
参考: Linux下半部处理之软中断 linux中断底半部机制 <深入理解Linux内核>软中断/tasklet/工作队列 软中断和tasklet介绍 详解操作系统中断 Linux内核:中 ...
- Spring,Mybatis,Springmvc框架整合项目(第三部分)
一.静态资源不拦截 第二部分最后显示的几个页面其实都加载了css和js等文件,要不然不会显示的那么好看(假装好看吧),前面已经说了,我们在web.xml中配置了url的拦截形式是/,那么Dispatc ...
- Oracle从入门到精通(笔记)
一.Oracle11g概述 1.6 启动与关闭数据库实例 1.6.1 启动数据库实例 Oracle数据库实例启动分3个步骤:启动实例,加载数据库,打开数据库: 命令格式:startup [nomoun ...
- 转:深入 AngularUI Router
原文地址:http://www.ng-newsletter.com/posts/angular-ui-router.html ui-router: https://angular-ui.github. ...
- vm下-kali-linux-xfce-2018.1的简略安装
1.选择版本为 debian 系统,因为是kali是基于debian的linux发行版 2.在安装首页选择 Graphical install,图形化安装,之后会让选择语言,选择简体中文,中国等,这些 ...
- SQL server 事务实例
简单的SQLserver事务实例: 执行SQL 组合操作A.操作B,只有AB都执行成功时才提交事务,否则回滚事务. 测试数据表: --1.数据表A CREATE TABLE A( A1 VARCHAR ...
- xtu数据结构 C. Ultra-QuickSort
C. Ultra-QuickSort Time Limit: 7000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java ...
- document.execCommand
document.execCommand 在firefox浏览器执行不好,但是在其他浏览器有时候使用会非常方便. 比如在input标签中使用: onkeyup="if(isNaN(value ...
- mysqlbinlog备份和mysqldump备份
-bash : mysqldump: command not found -bash : mysqlbinlog:command not found 首先得知道mysql命令或mysqldump命令的 ...
- Ubuntu 终端命令整理
一.文件目录类 1.建立目录:mkdir 目录名 2.删除空目录:rmdir 目录名 3.无条件删除子目录: rm -rf 目录名 4.改变当前目录:cd 目录名 (进入用户home目录:cd ~:进 ...