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 ...
随机推荐
- 小数据池 is 和 ==的区别
小数据池 一.小数据池 1)代码块 python程序是由代码块构成的,一个代码块的文本作为pythont程序执行的单元 官方文档: A Python program is constructed fr ...
- Python9-函数-day9
初识函数定义与调用 def my_len(): i = 0 for k in s1: i +=1 return i #返回值 # s = 'tim' s1 = '班主任阿娇' length =my_l ...
- PYDay4-基本数据类型、字符串、元组、列表、字典
1.关于编码: utf-8 与gbk都是对Unicode 编码的简化,utf-8是针对所有语言的精简,gbk是针对中文的精简 py3默认字符集为UTF-8,取消了Unicode字符集,如后面的编程过程 ...
- apache下虚拟域名配置
在我们开发中通过虚拟域名来访问一个指定的项目确实很方便,接下来教大家如何通过手动的方式去配置虚拟域名(已apache服务器为例) 一.首页我们得找到host文件.windows下这个文件在c盘中WIN ...
- PHP 页面跳转的三种方式
第一种方式:header() header()函数的主要功能是将HTTP协议标头(header)输出到浏览器. 语法: void header ( string $string [, bool $re ...
- HDU 4417 Super Mario(划分树问题求不大于k的数有多少)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- c++ stack,queue,vector基本操作
stack 的基本操作有:入栈,如例:s.push(x);出栈,如例:s.pop();注意,出栈操作只是删除栈顶元素,并不返回该元素.访问栈顶,如例:s.top()判断栈空,如例:s.empty(), ...
- jsessionid 所引起的404问题和解决方法
问题: 在SpringMvc使用RedirectView或者"redirect:"前缀来做重定向时,Spring MVC最后会调用: response.sendRedirect(r ...
- ps 批量杀死进程
ps aux | grep xxx |awk '{print $2}'|xargs kill -9
- POJ——2449Remmarguts' Date(A*+SPFA)
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 26504 Accepted: 7203 ...