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 ...
随机推荐
- 算法竞赛中c++一些需要注意的错误
1. 关于精度: 取整 除法取整: (除数为正)被除数为正时系统除法为向下取整,被除数为负时系统除法为向上取整. 向上取整(被除数非负,除数为正): 一般写法(有bug): int cal(int x ...
- PAT Basic 1041
1041 考试座位号 每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码 ...
- kali2018 安装****
1.安装需要的依赖包: apt-get install qt5-qmake qtbase5-dev libqrencode-dev libappindicator-dev libzbar-dev ro ...
- i++和++i的区别,及其线程安全问题
i++和++i都是i=i+1的意思,但是过程有些许区别: i++:先赋值再自加.(例如:i=1:a=1+i++:结果为a=1+1=2,语句执行完后i再进行自加为2) ++i:先自加再赋值.(例如:i= ...
- 如何使用百度地图API
一.申请密钥 1.先用eclipse创建一个Android工程 2.在百度api官网上申请一个密钥,链接:http://lbsyun.baidu.com/apiconsole/key 二.工程配置 1 ...
- iRule Event Order - HTTPSv7
v
- iOS控件-3级城市列表-plist版
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- Snmp的学习总结(二)
一.SNMP简介 SNMP指的是简单网络管理协议.它属于TCP/IP五层协议中的应用层协议.它提供了一种简单和方便的模式来管理网络中的各个元素.这里的元素就是各个被管理的对象,可以是因特网中的某个硬件 ...
- hdu3038 How Many Answers Are Wrong
TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wo ...
- Spring-IOC源码解读1-整体设计
1. SpringIOC提供了一个基本的javabean容器,通过IOC模式管理依赖关系,并通过依赖注入和AOP增强了为javabean这样的pojo对象赋予事务管理,生命周期管理等基本功能.2. S ...