在了解了初始化工程后,现在我们可以开始开发简单的界面了,这里我们将以下图界面为例举例,搭建界面并实现点击搜索框跳转到搜索页面,点击分类的页面跳转到对应的分类列表页

weex-components

在编写界面时,我可能会用到wxc-navpage、wxc-tabbar等组件,因此我们首先需要在工程的根目录下安装weex-components:

$ npm install  weex-components

并在需要的页面的script里引用weex-components

require('weex-components');

搜索框

我们可以将页面中比较通用的部分单独提出来写成一个we文件,这里我们将搜索框单独提出来,命名为search.we

搜索框中的内容可能会由于页面不一样而不一样,则需要我们用{{text}}来代替要写的内容,由其他页面将text的值传入,并在该we文件的script中声明

      data:{text:''},

要实现页面跳转,首先在created方法中获取到this.baseURL,然后在跳转的函数中拼接路径。并引入navigator = require(‘@weex-module/navigator’);组件,然后使用push方法,将路由对象添加进了路由栈。

获取到this.baseURL

var bundleUrl = this.$getConfig().bundleUrl;bundleUrl = new String(bundleUrl);var nativeBase;var isAndroidAssets = bundleUrl.indexOf('file://assets/') >= 0;var isiOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('WeexDemo.app') > 0;if (isAndroidAssets) {nativeBase = 'file://assets/dist/';}else if (isiOSAssets) {nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1);}else {var host = 'localhost:8080';var matches = /\/\/([^\/]+?)\//.exec(bundleUrl);if (matches && matches.length >= 2) {host = matches[1];}nativeBase = 'http://' + host + '/index.html?page=./dist/';}this.baseURL = nativeBase;

在opensearchpage方法中实现页面跳转

opensearchpage: function(e){var navigator = require('@weex-module/navigator');var params = {'url': this.baseURL+'modules/searchpage.js','animated' : 'true'}navigator.push(params, function(e) {});}

search.we整体代码如下:

<template><div class="center" style="flex-direction: row;  position: absolute;  top: 0px; left: 0px; right: 0px; height: 100px; background-color:#ffffff;"><div class="searchhole" style="flex:1;flex-direction: row; align-items:center;" onclick="opensearchpage"><text style="flex:0.92;margin-left: 15px;color: gainsboro">{{text}}</text><image style="flex:0.08;margin-right:15px;width: 50px;height: 50px;" src="http://photo.yupoo.com/zpfvs1/G3Gxmx9X/small.jpg" ></image></div></div>
</template><style>.center {justify-content: center;align-items: center;}.searchhole {height:75px;background-color: #ffffff;margin-left: 50px;margin-right: 50px;border-width:2px;border-color:#F8BB2D;border-radius:40px;}
</style><script>require('weex-components');module.exports = {data:{baseURL: '',text:''},created: function(){var bundleUrl = this.$getConfig().bundleUrl;bundleUrl = new String(bundleUrl);var nativeBase;var isAndroidAssets = bundleUrl.indexOf('file://assets/') >= 0;var isiOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('WeexDemo.app') > 0;if (isAndroidAssets) {nativeBase = 'file://assets/dist/';}else if (isiOSAssets) {nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1);}else {var host = 'localhost:8080';var matches = /\/\/([^\/]+?)\//.exec(bundleUrl);if (matches && matches.length >= 2) {host = matches[1];}nativeBase = 'http://' + host + '/index.html?page=./dist/';}this.baseURL = nativeBase;},methods: {opensearchpage: function(e){var navigator = require('@weex-module/navigator');var params = {'url': this.baseURL+'modules/searchpage.js','animated' : 'true'}navigator.push(params, function(e) {});}}};
</script>

我们将分类页命名为main.we,首先需要在script中引用刚刚写好的search.we文件

require('./search.we');

并在template中加载搜索框并对搜索框的text赋值

<search text="我想要的书"></search>

若想使分布那块的界面可以实现上下滑动的效果,可以把该部分HTML写在list中

<list></list>

这里界面有许多重复的部分,我们则可以使用repeat={{itemrow}}来实现,重复部分不同的数据在script的data中声明

要实现不同分类跳转到分类列表页中显示对应分类的内容,我们需要先在HTML中添加titile的属性,并在点击后识别出点击的部分的title,_getType(title)方法只用于实现将中文换为拼音

var obj = e.target.attr;
var title = obj.title;
var type = this._getType(title);

并在路径中需要多拼接该值用于之后页面显示内容的判定

'url': this.baseURL+'modules/booklist.js?type='+type,

根据titile实现对应页面跳转

openbooklist: function (e) {var navigator = require('@weex-module/navigator');var obj = e.target.attr;var title = obj.title;var type = this._getType(title);var params = {'url': this.baseURL+'modules/booklist.js?type='+type,'animated' : 'true'}navigator.push(params, function(e) {});},_getType: function(title){var type = 'it';switch(title){case '教材':type = 'jiaocai';break;case '计算机':type = 'jisuanji';break;case '考研':type = 'kaoyan';break;case '外语':type = 'waiyu';break;case '公务员':type = 'gongwuyuan';break;case '其他':type = 'qita';break;default:break;}return type;}

main.we整体代码如下:

<template><div class="bg"><search text="我想要的书"></search><list class="mainlist"><cell class="cell" repeat={{itemrow}} style="flex-direction:row;"><div style="flex:0.5; flex-direction:row; background-color:#ffffff;margin-right: 2px;" onclick="openbooklist" title="{{texts0}}"><div style="flex:0.5;"><image class="img" src="{{imgs0}}" /></div><div class="center" style="flex:0.5;"><text class="texttitle">{{texts0}}</text><text class="textnum">{{nums0}}</text></div></div><div style="flex:0.5; flex-direction:row; background-color:#ffffff;margin-left: 2px;" onclick="openbooklist" title="{{texts1}}"><div style="flex:0.5;"><image class="img" src="{{imgs1}}" /></div><div class="center" style="flex:0.5;"><text class="texttitle">{{texts1}}</text><text class="textnum">{{nums1}}</text></div></div></cell></list></div>
</template><style>.bg {background-color: #F0EFF4;}.mainlist{top: 104px;left: 0;right: 0;bottom: 85px;}.cell {padding-top: 4px;padding-bottom: 0;height:254px;}.center {justify-content: center;align-items: center;}.img{height: 250px;width: 100%;}.texttitle{font-size: 26px;font-weight:300;color:#414141;}.textnum{font-size: 26px;font-weight:300;margin-top: 30px;color:#414141;}
</style><script>require('./search.we');module.exports = {data:{baseURL: '',itemrow: [{index: 0,imgs0:'http://photo.yupoo.com/zpfvs1/G3Gubo2K/small.jpg',texts0: '教材',nums0: '4',src0:'',imgs1: 'http://photo.yupoo.com/zpfvs1/G3GuaUux/small.jpg',texts1: '计算机',nums1: '2',src1:''},{index: 1,imgs0:'http://photo.yupoo.com/zpfvs1/G3Guc3Qd/small.jpg',texts0: '考研',nums0: '2',src0:'',imgs1: 'http://photo.yupoo.com/zpfvs1/G3GubFmS/small.jpg',texts1: '外语',nums1: '3',src1:''},{index: 2,imgs0:'http://photo.yupoo.com/zpfvs1/G3Gubs6D/small.jpg',texts0: '公务员',nums0: '0',src0:'',imgs1: 'http://photo.yupoo.com/zpfvs1/G3GucetH/small.jpg',texts1: '其他',nums1: '1',src1:''}]},created: function(){var bundleUrl = this.$getConfig().bundleUrl;bundleUrl = new String(bundleUrl);var nativeBase;var isAndroidAssets = bundleUrl.indexOf('file://assets/') >= 0;var isiOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('WeexDemo.app') > 0;if (isAndroidAssets) {nativeBase = 'file://assets/dist/';}else if (isiOSAssets) {nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1);}else {var host = 'localhost:8080';var matches = /\/\/([^\/]+?)\//.exec(bundleUrl);if (matches && matches.length >= 2) {host = matches[1];}nativeBase = 'http://' + host + '/index.html?page=./dist/';}this.baseURL = nativeBase;},methods:{openbooklist: function (e) {var navigator = require('@weex-module/navigator');var obj = e.target.attr;var title = obj.title;var type = this._getType(title);var params = {'url': this.baseURL+'modules/booklist.js?type='+type,'animated' : 'true'}navigator.push(params, function(e) {});},_getType: function(title){var type = 'it';switch(title){case '教材':type = 'jiaocai';break;case '计算机':type = 'jisuanji';break;case '考研':type = 'kaoyan';break;case '外语':type = 'waiyu';break;case '公务员':type = 'gongwuyuan';break;case '其他':type = 'qita';break;default:break;}return type;}}};
</script>

在分类列表页读取URL中type的值

在sciprt的created方法中对调用methods中的getParameterByName方法,contentType就是我们需要的type的值

var contentType=this.getParameterByName('type',bundleUrl);

getParameterByName方法

getParameterByName: function (name, url) {name = name.replace(/[\[\]]/g, "\\$&");var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),results = regex.exec(url);if (!results) return null;if (!results[2]) return '';return decodeURIComponent(results[2].replace(/\+/g, " "));},

WEEX|简单界面的实现与页面跳转相关推荐

  1. php中跳到指定界面_php如何实现页面跳转

    PHP跳转到指定页面的问题通常都会建设网站需求上看到,比如我们需要从一个页面跳转到另一个页面来实现某个功能或者效果.其实在PHP中进行页面跳转是有多种方法的,那么这篇文章就给大家介绍下,有哪些方法可以 ...

  2. android界面实现框架内页面跳转_KVM虚拟化管理平台的实现

    KVM虚拟化管理平台的实现 源码链接:https://github.com/wsjhk/IaaS_admin.git 视频演示链接:https://v.youku.com/v_show/id_XMjg ...

  3. swift 原生给h5发消息_Swift-WKWebView与JavaScript的细节,H5页面跳转原生界面

    大家(也包括我)要学会 明白一件事情(注意断句,哈哈).优秀的程序猿会将问题简单化. 世界上有10种人,一种是先把问题复杂化,然后在一点点的做减法:另一种是先把问题简单化,然后在慢慢的做加法:(好了该 ...

  4. SwiftUI——界面间的“闪转腾挪”(页面跳转的各种方法)

    在开发过程中,我们经常需要在多个界面之间"闪转腾挪",在SwiftUI有两种方法: NavigationView法:最常见的方法.每层之间都可以传递数据.由于是一层一层界面跳转,不 ...

  5. 入门攻略丨教你用低代码实现一个简单的页面跳转功能

    一.介绍 HUAWEI DevEco Studio(后文简称:IDE)自2020年9月首次发布以来,经10次迭代升级,不断为HarmonyOS应用开发增强能力.3月31日,IDE再度升级到DevEco ...

  6. 转:ECharts图表组件之简单关系图:如何轻松实现另类站点地图且扩展节点属性实现点击节点页面跳转...

    站点地图不外乎就是罗列一个网站的层次结构,提炼地讲就是一个关系结构图.那么我们如何巧用ECharts图表组件内的简单关系结构图来实现一个站点的地图结构呢?另外如何点击某个节点的时候实现页面跳转呢? 针 ...

  7. 基于HBuilderX创建移动app项目并利用mui实现简单页面跳转

    刚开始学,听老师讲了一些介绍,要求我们做一个页面跳转,当时内心真的是万马奔腾,他的是使用什么icon的来实现的,但是我没看不懂怎么实现页面跳转的,就使用了mui来做了.百度了很多内容,杂七杂八的,所以 ...

  8. SSM框架,ajax实现登陆界面验证和登陆成功后页面跳转问题

    账号.密码和验证码都正确后,使用了ajax实现验证,验证结束后不能像正常一样返回一个字符串,用视图解析器来跳转页面 <!--配置JSP 显示ViewResolver(视图解析器)--> & ...

  9. uni-app简单应用和页面跳转

    uni-app简单应用和页面跳转 上篇写的HBuilderX 的安装和使用 https://blog.csdn.net/YaoChiZaoFan/article/details/106538651 这 ...

  10. 微信小程序--简单页面跳转

    微信小程序--简单页面跳转 例如:点击一个text ,跳转入一个新的页面blueberry.wxml 首先对text 设置监听事件 <view bindtap="toast" ...

最新文章

  1. 自动驾驶关键技术分解和流程
  2. 易买网的一些增删改查
  3. 清华北大南大全面“线上开学”,10 大直播神器齐亮相!
  4. C语言:一个涉及指针函数返回值与printf乱码、内存堆栈的经典案例
  5. C语言易错题集 第二部
  6. 有序序列中的i个最大数(算法导论思考题9-1)
  7. Win7电脑定时关机怎么设置
  8. 【软件质量】代码注释的消极作用
  9. mysql_install_db创建空库_MySQL数据库的初始化mysql_install_db
  10. 【软件测试】导致软件缺陷的最大原因是软件需求规格说明书
  11. [pion]写一个简单的turn服务器
  12. 企业级代码静态测试工具Helix QAC——Helix QAC Dashboard基于团队的工程质量管理系统/Helix QAC资质认证
  13. Excel怎么批量将各数据复制填充指定次数
  14. VS2017调用Matlab2016b进行绘图
  15. 2019年1月1日之后 你能少缴纳多少个税
  16. 微信,支付宝,收款二维码实时生成订单监控,免签支,付支付系统,个人收款,收款二维码...
  17. IDEA封神榜大语言模型二郎神系列Erlangshen-Ubert-110M-Chinese使用
  18. funcode实验--海底世界(c++实现)
  19. 心脏滴血(CVE-2014-0160)
  20. 五十一个经典小故事2

热门文章

  1. rsync内网服务器 推送和拉取公网代码配置
  2. 【翻译】Ext JS 5的委托事件和手势
  3. Sorry sir!
  4. 22_粗粒度权限控制
  5. CF991E Bus Number
  6. 基于python 爬虫_基于python的爬虫(一)
  7. vue的下拉框如何回显_JAVA学习笔记系列:菜鸟Vue学习笔记(三)
  8. jar包导入本地maven仓库
  9. c++ opengl 绘制地面_铝合金门窗设计之绘制节点图
  10. 学linux哪个版本号,初学Linux哪个发行版本好?这些更合适!