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 ...
随机推荐
- saltstack系列2之zabbix-agent自动化部署
实施前提条件 zabbix-agent通过编译安装的,打成tar包,并且自己先配好master的ip等等之类的配置在/etc下,然后我们后面只需要修改一个Hostname这个配置项即可.. salts ...
- sql server 2005 怎么看是不是企业版
已经安装了SQL server 2005 怎么确定它是企业版 还是标准版??? 执行sql:SELECT @@VERSION在结果里看,比如我这里是(里面有Enterprise Edition,表示企 ...
- 关于HTML标签嵌套的问题详解
先说基础,HTML标签有两类: 1.块级元素 div.h1~h6.address.blockquote.center.dir.dl.dt.dd.fieldset.form.hr.isindex.men ...
- [Bayes] What is Sampling
Ref: http://blog.csdn.net/xianlingmao/article/details/7768833 通常,我们会遇到很多问题无法用分析的方法来求得精确解,例如由于式子特别,真的 ...
- AES-128-CBC加密
C#: public static string AesKey = "sgg45747ss223455"; /// <summary> /// AES加密 (128-C ...
- Java -- 异常的捕获及处理 -- Exception类与RuntimeException类
7.3 Exception类与RuntimeException类 Exception类与RuntimeException类的联系与区别??? 例:字符串变为整型 Class : RuntimeExce ...
- 8 -- 深入使用Spring -- 2...3 使用@Resource配置依赖
8.2.3 使用@Resource配置依赖 @Resource 位于javax.annotation包下,是来自Java EE规范的一个Annotation,Spring直接借鉴了该Annotatio ...
- Discuz!X 3.4 任意文件删除漏洞复现过程(附python脚本)
今天看下群里在讨论Discuz!X 3.4 任意文件删除漏洞,自己做了一些测试,记录一下过程.结尾附上自己编写的python脚本,自动化实现任意文件删除. 具体漏洞,请查看 https://paper ...
- Cesium加载影像和地形数据+开启高程遮挡效果+视点定位+定时更新
// 初始化Cesium var viewer = new Cesium.Viewer('cesiumContainer', { /*imageryProvider : new Cesium.ArcG ...
- Jar命令
JAR包是Java中所特有一种压缩文档,其实大家就可以把它理解为.zip包;当然也是有区别的,JAR包中有一个META-INF\MANIFEST.MF文件,当你打成JAR包时,它会自动生成. 一.ja ...