weexapp 开发流程(二)框架搭建
1.创建 入口文件
src / entry.js
/**
* 入口文件
*/
import App from './App.vue'
import router from './router'
// import { sync } from 'vuex-router-sync'
import * as filters from './filters'
import mixins from './mixins' // sync the router with the vuex store.
// this registers `store.state.route`
// sync(store, router) // register global utility filters.
Object.keys(filters).forEach(key => {
Vue.filter(key, filters[key])
}) // register global mixins.
Vue.mixin(mixins) import VueResource from 'vue-resource'
Vue.use(VueResource)
// create the app instance.
// here we inject the router and store to all child components,
// making them available everywhere as `this.$router` and `this.$store`.
new Vue(Vue.util.extend({ el: '#root', router }, App)); router.push('/');
2.创建 主页面 底部选项卡 工具类
(1)创建主页面
src / App.vue
<!-- 主页面 底部选项卡 -->
<template>
<div class="app-wrapper">
<router-view class="r-box"></router-view>
<tab-bar @tabTo="onTabTo"></tab-bar>
</div>
</template> <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> <script>
// 弹窗
var modal = weex.requireModule('modal');
// 工具类
import util from './assets/util';
// 底部选项卡组件
import tabBar from './assets/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>
(2)创建 底部选项卡 组件
src / assets / components / 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('top')">
<text class="bar-ic iconfont"></text>
<text class="bar-txt">推荐</text>
</div>
<div class="bar-item act" @click="tabTo('demo')">
<text class="bar-ic iconfont"></text>
<text class="bar-txt">分类</text>
</div>
<div class="bar-item" @click="tabTo('all')">
<text class="bar-ic iconfont"></text>
<text class="bar-txt">PHP教程</text>
</div>
<div class="bar-item" @click="tabTo('my')">
<text class="bar-ic iconfont"></text>
<text class="bar-txt">关于</text>
</div>
</div>
</template> <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: 7px;
font-size: 38px;
}
.bar-txt{
font-size: 22px;
padding-top: 1px;
}
</style> <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>
其他页面,例如:首页
src / assets / views / home.vue
<!-- 首页 -->
<template>
<div>
<text>首页</text>
</div>
</template> <style scoped> </style> <script>
export default {
data () {
return {
}
}
}
</script>
(3)创建 工具类
src / assets / util.js
/**
* 工具类
*/
let utilFunc = {
initIconFont () {
let domModule = weex.requireModule('dom');
domModule.addRule('fontFace', {
'fontFamily': "iconfont",
'src': "url('http://at.alicdn.com/t/font_493435_f28oeelm5i8xs9k9.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;
3.创建 路由
src / router.js
/**
* 配置路由
*/
import Router from 'vue-router'
// 首页
import ViewHome from './assets/views/home.vue'
// 关于
import ViewMy from './assets/views/my.vue'
// PHP教程
import ViewAll from './assets/views/all.vue'
// 分类
import Viewdemo from './assets/views/demo.vue'
// 推荐
import ViewTopbvive from './assets/views/top.vue' Vue.use(Router) export default new Router({
// mode: 'abstract',
routes: [
// 默认页面 首页
{
path: '/',
redirect: '/home'
},
// 首页
{
path: '/home',
component: ViewHome
},
// 关于
{
path: '/my',
component: ViewMy
},
// 分类
{
path: '/demo',
component: Viewdemo
},
// PHP教程
{
path: '/all',
component: ViewAll
},
// 推荐
{
path: '/top',
component: ViewTopbvive
}
]
})
4.创建 公用过滤器 filters
src / filters / index.js
export function host (url) {
if (!url) return ''
const host = url.replace(/^https?:\/\//, '').replace(/\/.*$/, '')
const parts = host.split('.').slice(-3)
if (parts[0] === 'www') parts.shift()
return parts.join('.')
}
export function https (url) {
const env = weex.config.env || WXEnvironment
if (env.platform === 'iOS' && typeof url === 'string') {
return url.replace(/^http\:/, 'https:')
}
return url
}
export function timeAgo (time) {
const between = Date.now() / 1000 - Number(time)
if (between < 3600) {
return pluralize(~~(between / 60), ' minute')
} else if (between < 86400) {
return pluralize(~~(between / 3600), ' hour')
} else {
return pluralize(~~(between / 86400), ' day')
}
}
function pluralize (time, label) {
if (time === 1) {
return time + label
}
return time + label + 's'
}
export function unescape (text) {
let res = text || ''
;[
['<p>', '\n'],
['&', '&'],
['&', '&'],
[''', '\''],
[''', '\''],
['/', '/'],
[''', '\''],
['/', '/'],
['<', '<'],
['>', '>'],
[' ', ' '],
['"', '"']
].forEach(pair => {
res = res.replace(new RegExp(pair[0], 'ig'), pair[1])
})
return res
}
5.创建 混合 mixins
src / mixins / index.js
export default {
methods: {
jump (to) {
if (this.$router) {
this.$router.push(to)
}
}
}
}
6.效果图

weexapp 开发流程(二)框架搭建的更多相关文章
- Angular企业级开发(5)-项目框架搭建
1.AngularJS Seed项目目录结构 AngularJS官方网站提供了一个angular-phonecat项目,另外一个就是Angular-Seed项目.所以大多数团队会基于Angular-S ...
- WebX框架学习笔记之二----框架搭建及请求的发起和处理
框架搭建 执行环境:windows.maven 执行步骤: 1.新建一个目录,例如:D:\workspace.注意在盘符目录下是无法执行成功的. 2.执行如下命令: mvn archetype:gen ...
- sonne_game网站开发02spring+mybatis框架搭建
从最开始搭框架谈起,而且,我不仅仅会讲how,还会努力讲why.因为对于web开发,由于有太多好的框架.组件.工具,使得how往往不是那么深刻,背后的why更值得专研.如果有初学者关注我这个系列,也一 ...
- c语言项目开发流程二部曲
一.在第一部曲中我们介绍了电子词典项目开发的前5步,下面继续我们的步伐. 6.函数接口设计,这一步不是一蹴而就的,在项目进行中得不断修改,下面是我电子词典项目接口. /**************函数 ...
- weexapp 开发流程(一)开发环境配置
1.创建项目 weexpack create weexapp 2.安装必要插件 npm i jwt-simple vue-resource vue-router vuex vuex-router-sy ...
- [libgdx游戏开发教程]使用Libgdx进行游戏开发(2)-游戏框架搭建
让我们抛开理论开始code吧. 入口类CanyonBunnyMain的代码: package com.packtpub.libgdx.canyonbunny; import com.badlogic. ...
- weexapp 开发流程(三)其他页面创建
1.首页 (1)轮播图 步骤一:创建 轮播图 组件(Slider.vue) src / assets / components / Slider.vue <!-- 轮播图 组件 --> & ...
- SOA架构商城二 框架搭建
1.创建父工程 创建Maven工程pingyougou-parent,选择packaging类型为pom ,在pom.xml文件中添加锁定版本信息dependencyManagement与plugin ...
- jeesite快速开发平台(二)----环境搭建
转自:https://blog.csdn.net/u011781521/article/details/54880465
随机推荐
- leetcode-3-basic-divide and conquer
解题思路: 因为这个矩阵是有序的,所以从右上角开始查找.这样的话,如果target比matrix[row][col]小,那么就向左查找:如果比它大,就 向下查找.如果相等就找到了,如果碰到边界,就说明 ...
- Errors occurred during the build. Errors running builder 'JavaScript Validator'
选择一个项目--右键Properties--Builders--取消第2个"JavaScript Validator"的勾就OK了.
- !!注意!部署出现the requested resource is not available
避免项目里重复包出现 同时tomcat的lib里避免重复包,也会出现requested resource isnot available!
- 83. Spring Boot 1.4单元测试【从零开始学Spring Boot】
在[27. Spring Boot Junit单元测试]中讲过1.3版本的单元测试方式,这里说说1.4和1.3有什么区别之处? 在1.3中单元测试这样子的类似代码: //// SpringJUnit支 ...
- 【luogu】P1772物流运输(最短路+DP)
题目链接 对于本题我们设ext[i][j]计算第i个码头在前j天总共有几天不能用(其实就一前缀和),设dis[i][j]是从第i天到第j天不变运输路线的最短路径,设f[i]是前i天运输货物的最小花费. ...
- 如何构建一个flink sql平台
在本系列前面的文章中,简单介绍了一下Ignite的机器学习网格,下面会趁热打铁,结合一些示例,深入介绍Ignite支持的一些机器学习算法. 如果要找合适的数据集,会发现可用的有很多,但是对于线性回归来 ...
- spring之lazy-init
lazy-init:延迟实例化 ApplicationContext实现的默认行为就是在启动服务器时将所有singleton bean提前进行实例化.提前实例化意味着作为初始化过程的一部分,appli ...
- 转载:CreateMutex WaitForSingleObject ReleaseMutex使用
HANDLE CreateMutex( LPSECURITY_ATTRIBUTES lpMutexAttributes,// BOOL bInitialOwner, // flag for init ...
- 开店 BZOJ 4012
开店 [问题描述] 风见幽香有一个好朋友叫八云紫,她们经常一起看星星看月亮从诗词歌赋谈到人生哲学.最近她们灵机一动,打算在幻想乡开一家小店来做生意赚点钱.这样的想法当然非常好啦,但是她们也发现她们面临 ...
- PXC小结
PXC使用到的端口号 3306 数据库对外服务的端口号(视具体情况而定) 4444 请求SST SST: 指数据一个镜象传输 xtrabackup , rsync ,mysqldump 4567 : ...