weex 项目开发(五)自定义 过滤函数 和 混合 及 自定义 Header 组件
1.自定义 过滤函数
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
}
2.自定义 混合 函数
src / mixins / index.js
/**
* 混合
*/
export default {
methods: {
jump (to) {
if (this.$router) {
this.$router.push(to)
}
}
}
}
3.自定义 Header 组件
src / components / Header.vue
Header.vue
<!-- Header 组件 -->
<template>
<div class="wrapper">
<div class="scan">
<text class="ic iconfont"></text>
<text class="txt">扫一扫</text>
</div>
<text class="search iconfont" @click="jumpWeb()"> 搜索商品,共8888款好物</text>
<div class="notice">
<text class="ic iconfont"></text>
<text class="txt">消息</text>
</div>
</div>
</template> <script>
var navigator = weex.requireModule('navigator');
import util from '../utils/util.js'; export default {
data () {
return {
//
}
},
created () {
//
},
methods: {
jumpWeb (_url) {
if(!_url) _url = 'http://m.you.163.com/search';
const url = this.$getConfig().bundleUrl;
navigator.push({
url: util.setBundleUrl(url, 'page/webview.js?weburl='+_url) ,
animated: "false"
});
}
}
}
</script> <style scoped>
.iconfont {
font-family:iconfont;
}
.wrapper{
position: fixed;
top: 0;
left: 0;right: 0;
height: 114px;
padding-top: 34px;
display:flex;
flex-wrap: nowrap;
flex-direction: row;
justify-content: space-around;
z-index: 101;
background-color: #fafafa;
opacity: .99;
}
.scan,.notice{
height: 80px;
width: 96px
}
.ic,.txt,.search{
text-align: center;
color:#666;
font-weight: 300;
}
.ic{
font-size: 32px;
}
.txt{
font-size: 18px;
}
.search {
flex: 1;
height: 60px;
font-size: 26px;
padding-top: 13px;
background-color: #ededed;
border-radius: 8px;
}
</style>
4.页面调用
src / pages / Home / Home.vue
Home.vue
<!-- 首页 -->
<template>
<div>
<!-- 顶部标题栏 -->
<home-header></home-header>
</div>
</template> <script>
import Header from '../../components/Header.vue'; export default {
name: 'Home',
components: {
'home-header': Header,
},
data: () => ({
//
}),
created () {
//
},
methods: {
//
}
};
</script>
5.效果图
weex 项目开发(五)自定义 过滤函数 和 混合 及 自定义 Header 组件的更多相关文章
- weex 项目开发(三) weexpack + weex-ui
github地址:weex-ui https://github.com/alibaba/weex-ui 官网: https://alibaba.github.io/weex-ui/#/cn/ 创建项目 ...
- weex 项目开发(四)项目框架搭建 及 自定义 TabBar 组件
1.安装 路由模块 及 状态管理模块 npm install vue-router --save npm install vuex --save 2.自定义 TabBar 组件 src / ...
- [php笔记]项目开发五个阶段/雇员管理系统
zend 公司,管理PHP版本的升级. 功能强大, 官方推荐. (开发一个PHP项目) 软件开发的五个阶段. 1.创建一个项目(工程)2.设置该项目的路径3.创建一个文件test.php ***使用Z ...
- weex 项目开发 weexpack 项目 打包、签名、发布
一. weexpack build android 和 weexpack run android 的 区别. (1)单纯打包 weexpack build android (2)打包并运行 wee ...
- weex 项目开发(六)weexpack 项目 打包、签名、发布
一. weexpack build android 和 weexpack run android 的 区别. (1)单纯打包 weexpack build android (2)打包并运行 wee ...
- weex 项目开发(二) weex 与 weexpack 的区别
1.weex 与 weexpack 即 weex-toolkit 与 weexpack 的区别 weex-toolkit 初始化的项目是针对开发单个 Weex 页面而设计的,也就是说这样的项目只包括 ...
- weex 项目开发(一) weex create project 与 weex init project 的区别
开发环境配置:http://www.cnblogs.com/crazycode2/p/7822961.html 1. weex create project 与 weex init project ...
- JAVA项目从运维部署到项目开发(五. Nginx)
<Nginx与Nginx-rtmp-module搭建RTMP视频直播和点播服务器>一文简单介绍了关于直播数据流的nginx相关配置,下面简单介绍下各种项目如何配置nginx. web项目. ...
- Android项目开发五-《星星生活志》1.使用MediaRecorder录制音频
Android设备实现录制音频的简单demo 转载请注明; http://blog.csdn.net/u013670933/article/details/26089487 代码例如以下: publi ...
随机推荐
- logging日志模块,四种方式
1.最简单的用法 import logging logging.error("hah") logging.info("hah") logging.debug(& ...
- Repo command reference
Repo command reference In this document init sync upload diff download forall prune start status Rep ...
- CSS布局基础--BFC
1,什么是BFC BFC(Block Formatting Context)块级格式化上下文,它就是一个环境,HTML元素在这个环境中按照一定规则进行布局.一个环境中的元素不会影响到其他环境中的布局. ...
- [转]构建Python+Selenium2自动化测试环境(二)
构建Python+Selenium2自动化测试环境完成之后,就需要测试支持python的selenium的版本是否都支持在不同浏览器上运行,当前我们分别在三个最通用的浏览器上通过脚本来测试. 1.在I ...
- Eclipse安装以及安装时遇到的问题解决办法
1, 首先要安装JDK(最好使用最新版本),注意区分32位于64位 2, 安装程序,双击打开安装即可 3, 安装包下载:http://developer.android.com/sdk/index.h ...
- Mac 文档阅读软件Dash软件破解版
1.Dash 破解版链接 Mac 上阅读开发文档的软件:支持java.spring.springBoot等.百度网盘下载链接和密码如下. 链接:https://pan.baidu.com/s/1RWM ...
- BNU OJ 1027 金币系统
金币系统 Time Limit: 1000ms Memory Limit: 65535KB 64-bit integer IO format: %lld Java class name: ...
- 30分钟学会如何使用Shiro(转自:http://www.cnblogs.com/learnhow/p/5694876.html)
本篇内容大多总结自张开涛的<跟我学Shiro>原文地址:http://jinnianshilongnian.iteye.com/blog/2018936 我并没有全部看完,只是选择了一部分 ...
- [luoguP1131] [ZJOI2007]时态同步(贪心)
传送门 显然是一棵树. 又显然一段一段地增加比较优. 我们可以dfs,并且尽量把每一个节点所有子树中所有节点的时间增加到一样. #include <vector> #include < ...
- django-Ajax发送POST请求-csrf跨站请求的三种方式
第一种 <script> $(".eq").on("click",function () { $.ajax({ url:"/eq/&quo ...