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 ...
随机推荐
- linux时钟概念CST与UTC、以及NTP简单设置
1.世界协调时间(Universal Time Coordinated,UTC): GPS 系统中有两种时间区分,一为UTC,另一为LT(地方时)两者的区别为时区不同,UTC就是0时区的时间,地方时为 ...
- 【Linux】网卡配置与绑定
Redhat Linux的网络配置,基本上是通过修改几个配置文件来实现的. 虽然也可以用ifconfig来设置IP,用route来配置默认网关,用hostname来配置主机名,但是重启后会丢失. 相关 ...
- luogu1879 [USACO06NOV]玉米田Corn Fields
学习位运算 #include <iostream> #include <cstdio> using namespace std; int n, m, dp[15][4105], ...
- intellij idea 17 log4j 中文乱码
先是在intellij idea里设置没有得到解决, 然后在tomcat的server.xml里设置没有得到解决, 再然后在log4j配置文件里配置没有得到解决. 以下是解决方案. C:\Progra ...
- Visual Studio 2013 滚动条实现代码缩略图
启动Visual studio 2013,打开工具->选项 在搜索选项输入,滚动条,英文版大概输入Scroll bar or Scroll 或者:文本编辑器->所有语言->滚动条 ...
- lua-helloworld
write script file, a.lua: #!/usr/bin/lua print("hello world!") add excutable prperty to th ...
- 【JavaScript 14—学习总结】:从小事做起
导读:花了将近两个月,JavaScript的学习视频算是做完了.里面的例子,都敲过一遍,但有少数的几个就是实现不了,比如:百度分享侧栏随着滚动条移动:菜单切换只对第一个起作用等,也就先放着了.现在,就 ...
- XML文件的操作说明
说明:C#中XmlNode与XmlElement的区别如下:xmlnode类表示xml文档中的单个节点,其命名空间为:System.Xml.XmlNode的三个最主要的子类包括:XmlDocument ...
- hdu6060[贪心+dfs] 2017多校3
/* hdu6060[贪心+dfs] 2017多校3*/ #include <bits/stdc++.h> using namespace std; typedef long long L ...
- 【Luogu】P3402最长公共子序列(LCS->nlognLIS)
题目链接 SovietPower 的题解讲的很清楚.Map或Hash映射后用nlogn求出LIS.这里只给出代码. #include<cstdio> #include<cctype& ...