mui---子页面调用父页面的自定义方法
目前在开发APP的时候,有这样的一个需求:需要在登录页面返回后能够刷新父页面。
功能是这样的:在 A.html页面有头像和用户昵称,这些信息需要用户进行登录才能够拿到,登录页面是在B.html,点击A.html页面,跳转到B.html进行登录,在B.html登录成功后返回,返回的时候需要更新A.html的头像和用户昵称。
方法:在B.html页面点击返回的时候,触发A.html页面的自定义方法来实现。
具体看代码:项目是用VUE来做的,所以...
B.html :添加 beforeback方法:
mounted: function(){
mui.init({
beforeback:function(){
var list = plus.webview.getWebviewById('music-index.html');
mui.fire(list,'refresh');
return true;
},
});
},
A.html 做接受这个方法,当然这个fire还可以进行传递参数
mounted: function() {
window.addEventListener('refresh',()=>{
console.log('refresh fun');
this.initialize(); // 具体方法
});
},
简答示例:a.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<link rel="stylesheet" type="text/css" href="../css/mui.min.css">
<style type="text/css">
*{margin:0px; padding:0px;}
div.main{width: 100%; position: absolute; top:0px; right:0px; bottom:0px; left:0px; background:#eee;}
div.main-scroll{width: 100%; position: absolute; top:0px; right:0px; bottom:0px; left:0px; overflow: scroll;}
ul.list{width: 100%;}
ul.list li{width: 100%; line-height: 40px; padding-left: 10px;}
</style>
</head>
<body>
<div class="main" id="main">
<div class="main-scroll">
<ul class="list">
<li v-for="x in list" @tap="details">{{x}}</li>
</ul>
</div>
</div>
</body>
<script type="text/javascript" src="../js/vue.min.js"></script>
<script type="text/javascript" src="../js/mui.min.js"></script>
<script type="text/javascript">
var main = new Vue({
el: "#main",
data: {
list:[],
num:0,
},
mounted: function() {
this.getList();
window.addEventListener('init',()=>{
this.initialize(); // location.reload();
});
},
watch: {},
methods: {
initialize:function(){
this.num ++;
this.getList();
},
getList:function(){
var lists = [];
for(var i=0; i<50; i++){
lists.push("第"+this.num+"个");
};
this.list = lists;
},
details:function(){
mui.openWindow({
url:'./a-details.html',
id:'a.html',
createNew:true,
styles:{top:'0px',bottom:'0px'},
show:{autoShow:true,aniShow:'slide-in-bottom',duration:260},
waiting:{autoShow:false,title:'',options:{}}
});
},
}
});
</script>
</html>
跳转到详情:a-details.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Document</title>
<link rel="stylesheet" type="text/css" href="../css/mui.css">
<style type="text/css">
div.main{width: 100%; position: absolute; top:0px; right:0px; bottom:0px; left:0px; background:#eee;}
div.main-scroll{width: 100%; position: absolute; top:0px; right:0px; bottom:0px; left:0px; overflow: scroll; background:orange;}
</style>
</head>
<body>
<div class="main">
<div class="main-scroll">
<button class="mui-action-back">点击返回</button>
</div>
</div>
<script type="text/javascript" src="../js/vue.min.js"></script>
<script type="text/javascript" src="../js/mui.min.js"></script>
<script type="text/javascript">
var main = new Vue({
el: "#main",
data: {
list:[],
},
mounted: function(){
mui.plusReady(()=>{
var selfWindow = plus.webview.currentWebview();
// 如果是固定的跳转 可以直接返回到固定的页面
// 如果点击进来的页面不固定 需要将点击来的页面ID传递过来
mui.init({
beforeback:function(){
var parent = plus.webview.getWebviewById('a.html');
// 还可以传值 mui.fire('home.html','init',{mid:3});
mui.fire(parent,'init');
return true;
},
});
});
},
watch: {},
methods: {
initialize:function(){
this.getUserInfo();
this.getMusicList();
this.getFigureList();
},
}
});
</script>
</body>
</html>
mui---子页面调用父页面的自定义方法的更多相关文章
- iframe子页面调用父页面javascript函数的方法
1.iframe子页面调用 父页面js函数 子页面调用父页面函数只需要写上window.parent就可以了.比如调用a()函数,就写成: window.parent.a(); 2.iframe父页面 ...
- 实现 iframe 子页面调用父页面中的js方法
父页面:index.html(使用iframe包含子页面child.html) [xhtml] view plaincopyprint? <html> <head> <s ...
- 使用iframe父页面调用子页面和子页面调用父页面的元素与方法
在实际的项目开发中,iframe框架经常使用,主要用于引入其他的页面.下面主要介绍一下使用iframe引入其他页面后,父页面如何调用子页面的方法和元素以及子页面如何调用父页面的方法和元素. 1.父页面 ...
- 如何通过js在子页面调用父页面元素的click事件
//获取父页面的某个元素var node = window.parent.document.getElementById("btnReturn");//调用该元素的Click事件 ...
- iframe弹出层中关闭包含iframe的div(子页面调用父页面js函数)
父页面: <div id="win2" style=" width:300px; height:200px; border:1px solid red;" ...
- iframe子页面调用父页面js函数
window.parent.document.getElementById("test").value; jQuery方法为: $(window.parent.document). ...
- mui---子页面主动调用父页面的方法
我们在做APP的时候,很多时候会有这样的功能需求,例如:登录,充值,如果登录成功,或充值成功后,需要更改当前页面以及父页面的状态信息,就会用到在子页面调用父页面的方法来实现:在子页面刷新父页面的功能. ...
- iframe页面调用父窗口JS函数
A页面iframe 页面B, 此时 如果要在B页面调用父页面A的函数 B页面写法 parent.functionName(); 错误1: 解决办法 var js_domain_async = 'bai ...
- easyUi弹出window窗口传值与调用父页面的方法,子页面给父页面赋值
<!-- 父页面 --> <!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "ht ...
随机推荐
- 使用monkey技术修改python requests模块
例如请求前和请求后各来一条日志,这样就不需要在自己的每个代码都去加日志了. 其实也可以直接记录'urllib3.connectionpool' logger name的日志. 修改了requests ...
- [Converge] Backpropagation Algorithm
Ref: CS231n Winter 2016: Lecture 4: Backpropagation Ref: How to implement a NN:中文翻译版本 Ref: Jacobian矩 ...
- SpringMVC由浅入深day02_10拦截器
10 拦截器 Spring Web MVC 的处理器拦截器类似于Servlet 开发中的过滤器Filter,用于对处理器进行预处理和后处理. 10.1 拦截定义 定义拦截器,实现HandlerInte ...
- Maven -- 发布jar包至远程仓库
啦啦啦
- VMWARE workstation 9 收缩虚拟硬盘
在9以前的版本中可以通过在客户机中vmtools收缩硬盘,而在9以后这个功能没有了.虚拟机中使用过的虚拟硬盘即使删除了所有数据,使用vmware workstation 9 的clean up dis ...
- 开发还是应该使用linux
这几天在Windows系统下,安装了几个IDE,体量大,4.5个G,启动速度慢,占用系统资源多,并且最难受的是,这些IDE的限制性太强,只能按照UI给定的规则来操作,例如现在手中有一个已完成的项目,用 ...
- SpringBoot application.properties (application.yml)优先级从高到低
SpringBoot application.properties(application.yml) 优先级从高到低 SpringBoot配置文件优先级从高到低 =================== ...
- Mysql Bypass小结
总结一些Bypass的方法, 1. 绕过空格过滤,使用注释/**/来替换 绕过安全狗简单的两个方法: /*'+'*/ /**a*/ 2.使用大小写绕过某些关键字的过滤 SeLeCT * From te ...
- C语言的f(open)函数(文件操作/读写)
头文件:#include <stdio.h> fopen()是一个常用的函数,用来以指定的方式打开文件,其原型为: FILE * fopen(const char * path, ...
- Java枚举根据key获取value
package com.utcip.crm.common.constants; import com.utcip.crm.common.base.process.ScheduleStatusEnum; ...