1.自定义  过滤函数

src / filters / index.js

  1. /**
  2. * 自定义 过滤函数
  3. */
  4. export function host (url) {
  5. if (!url) return ''
  6. const host = url.replace(/^https?:\/\//, '').replace(/\/.*$/, '')
  7. const parts = host.split('.').slice(-3)
  8. if (parts[0] === 'www') parts.shift()
  9. return parts.join('.')
  10. }
  11.  
  12. export function https (url) {
  13. const env = weex.config.env || WXEnvironment
  14. if (env.platform === 'iOS' && typeof url === 'string') {
  15. return url.replace(/^http\:/, 'https:')
  16. }
  17. return url
  18. }
  19.  
  20. export function timeAgo (time) {
  21. const between = Date.now() / 1000 - Number(time)
  22. if (between < 3600) {
  23. return pluralize(~~(between / 60), ' minute')
  24. } else if (between < 86400) {
  25. return pluralize(~~(between / 3600), ' hour')
  26. } else {
  27. return pluralize(~~(between / 86400), ' day')
  28. }
  29. }
  30.  
  31. function pluralize (time, label) {
  32. if (time === 1) {
  33. return time + label
  34. }
  35. return time + label + 's'
  36. }
  37.  
  38. export function unescape (text) {
  39. let res = text || ''
  40.  
  41. ;[
  42. ['<p>', '\n'],
  43. ['&', '&'],
  44. ['&', '&'],
  45. [''', '\''],
  46. [''', '\''],
  47. ['/', '/'],
  48. [''', '\''],
  49. ['/', '/'],
  50. ['<', '<'],
  51. ['>', '>'],
  52. [' ', ' '],
  53. ['"', '"']
  54. ].forEach(pair => {
  55. res = res.replace(new RegExp(pair[0], 'ig'), pair[1])
  56. })
  57.  
  58. return res
  59. }

2.自定义  混合 函数

src / mixins / index.js

  1. /**
  2. * 混合
  3. */
  4. export default {
  5. methods: {
  6. jump (to) {
  7. if (this.$router) {
  8. this.$router.push(to)
  9. }
  10. }
  11. }
  12. }

3.自定义  Header 组件

src / components / Header.vue

Header.vue

  1. <!-- Header 组件 -->
  2. <template>
  3. <div class="wrapper">
  4. <div class="scan">
  5. <text class="ic iconfont"></text>
  6. <text class="txt">扫一扫</text>
  7. </div>
  8. <text class="search iconfont" @click="jumpWeb()"> 搜索商品,共8888款好物</text>
  9. <div class="notice">
  10. <text class="ic iconfont"></text>
  11. <text class="txt">消息</text>
  12. </div>
  13. </div>
  14. </template>
  15.  
  16. <script>
  17. var navigator = weex.requireModule('navigator');
  18. import util from '../utils/util.js';
  19.  
  20. export default {
  21. data () {
  22. return {
  23. //
  24. }
  25. },
  26. created () {
  27. //
  28. },
  29. methods: {
  30. jumpWeb (_url) {
  31. if(!_url) _url = 'http://m.you.163.com/search';
  32. const url = this.$getConfig().bundleUrl;
  33. navigator.push({
  34. url: util.setBundleUrl(url, 'page/webview.js?weburl='+_url) ,
  35. animated: "false"
  36. });
  37. }
  38. }
  39. }
  40. </script>
  41.  
  42. <style scoped>
  43. .iconfont {
  44. font-family:iconfont;
  45. }
  46. .wrapper{
  47. position: fixed;
  48. top: 0;
  49. left: 0;right: 0;
  50. height: 114px;
  51. padding-top: 34px;
  52. display:flex;
  53. flex-wrap: nowrap;
  54. flex-direction: row;
  55. justify-content: space-around;
  56. z-index: 101;
  57. background-color: #fafafa;
  58. opacity: .99;
  59. }
  60. .scan,.notice{
  61. height: 80px;
  62. width: 96px
  63. }
  64. .ic,.txt,.search{
  65. text-align: center;
  66. color:#666;
  67. font-weight: 300;
  68. }
  69. .ic{
  70. font-size: 32px;
  71. }
  72. .txt{
  73. font-size: 18px;
  74. }
  75. .search {
  76. flex: 1;
  77. height: 60px;
  78. font-size: 26px;
  79. padding-top: 13px;
  80. background-color: #ededed;
  81. border-radius: 8px;
  82. }
  83. </style>

4.页面调用

src / pages / Home / Home.vue

Home.vue

  1. <!-- 首页 -->
  2. <template>
  3. <div>
  4. <!-- 顶部标题栏 -->
  5. <home-header></home-header>
  6. </div>
  7. </template>
  8.  
  9. <script>
  10. import Header from '../../components/Header.vue';
  11.  
  12. export default {
  13. name: 'Home',
  14. components: {
  15. 'home-header': Header,
  16. },
  17. data: () => ({
  18. //
  19. }),
  20. created () {
  21. //
  22. },
  23. methods: {
  24. //
  25. }
  26. };
  27. </script>

5.效果图

weex 项目开发(五)自定义 过滤函数 和 混合 及 自定义 Header 组件的更多相关文章

  1. weex 项目开发(三) weexpack + weex-ui

    github地址:weex-ui https://github.com/alibaba/weex-ui 官网: https://alibaba.github.io/weex-ui/#/cn/ 创建项目 ...

  2. weex 项目开发(四)项目框架搭建 及 自定义 TabBar 组件

    1.安装  路由模块  及  状态管理模块 npm install vue-router --save npm install vuex --save 2.自定义  TabBar  组件 src / ...

  3. [php笔记]项目开发五个阶段/雇员管理系统

    zend 公司,管理PHP版本的升级. 功能强大, 官方推荐. (开发一个PHP项目) 软件开发的五个阶段. 1.创建一个项目(工程)2.设置该项目的路径3.创建一个文件test.php ***使用Z ...

  4. weex 项目开发 weexpack 项目 打包、签名、发布

    一. weexpack build android  和  weexpack run android 的 区别. (1)单纯打包 weexpack build android (2)打包并运行 wee ...

  5. weex 项目开发(六)weexpack 项目 打包、签名、发布

    一. weexpack build android  和  weexpack run android 的 区别. (1)单纯打包 weexpack build android (2)打包并运行 wee ...

  6. weex 项目开发(二) weex 与 weexpack 的区别

    1.weex 与 weexpack 即  weex-toolkit 与 weexpack 的区别 weex-toolkit 初始化的项目是针对开发单个 Weex 页面而设计的,也就是说这样的项目只包括 ...

  7. weex 项目开发(一) weex create project 与 weex init project 的区别

    开发环境配置:http://www.cnblogs.com/crazycode2/p/7822961.html 1. weex create project  与  weex init project ...

  8. JAVA项目从运维部署到项目开发(五. Nginx)

    <Nginx与Nginx-rtmp-module搭建RTMP视频直播和点播服务器>一文简单介绍了关于直播数据流的nginx相关配置,下面简单介绍下各种项目如何配置nginx. web项目. ...

  9. Android项目开发五-《星星生活志》1.使用MediaRecorder录制音频

    Android设备实现录制音频的简单demo 转载请注明; http://blog.csdn.net/u013670933/article/details/26089487 代码例如以下: publi ...

随机推荐

  1. linux时钟概念CST与UTC、以及NTP简单设置

    1.世界协调时间(Universal Time Coordinated,UTC): GPS 系统中有两种时间区分,一为UTC,另一为LT(地方时)两者的区别为时区不同,UTC就是0时区的时间,地方时为 ...

  2. 【Linux】网卡配置与绑定

    Redhat Linux的网络配置,基本上是通过修改几个配置文件来实现的. 虽然也可以用ifconfig来设置IP,用route来配置默认网关,用hostname来配置主机名,但是重启后会丢失. 相关 ...

  3. luogu1879 [USACO06NOV]玉米田Corn Fields

    学习位运算 #include <iostream> #include <cstdio> using namespace std; int n, m, dp[15][4105], ...

  4. intellij idea 17 log4j 中文乱码

    先是在intellij idea里设置没有得到解决, 然后在tomcat的server.xml里设置没有得到解决, 再然后在log4j配置文件里配置没有得到解决. 以下是解决方案. C:\Progra ...

  5. Visual Studio 2013 滚动条实现代码缩略图

    启动Visual studio 2013,打开工具->选项   在搜索选项输入,滚动条,英文版大概输入Scroll bar or Scroll 或者:文本编辑器->所有语言->滚动条 ...

  6. lua-helloworld

    write script file, a.lua: #!/usr/bin/lua print("hello world!") add excutable prperty to th ...

  7. 【JavaScript 14—学习总结】:从小事做起

    导读:花了将近两个月,JavaScript的学习视频算是做完了.里面的例子,都敲过一遍,但有少数的几个就是实现不了,比如:百度分享侧栏随着滚动条移动:菜单切换只对第一个起作用等,也就先放着了.现在,就 ...

  8. XML文件的操作说明

    说明:C#中XmlNode与XmlElement的区别如下:xmlnode类表示xml文档中的单个节点,其命名空间为:System.Xml.XmlNode的三个最主要的子类包括:XmlDocument ...

  9. hdu6060[贪心+dfs] 2017多校3

    /* hdu6060[贪心+dfs] 2017多校3*/ #include <bits/stdc++.h> using namespace std; typedef long long L ...

  10. 【Luogu】P3402最长公共子序列(LCS->nlognLIS)

    题目链接 SovietPower 的题解讲的很清楚.Map或Hash映射后用nlogn求出LIS.这里只给出代码. #include<cstdio> #include<cctype& ...