Layui parent page to pass value to child page
There are many ways to pass values from the Layui parent page to the child page. I personally feel that this is relatively convenient.
- parent page code
var index = layer.open({
type: 2,
title: '编辑用户',
content: '/userUpdate',
area: ['100%', '100%'],
success: function(layero, index){
var iframe = window['layui-layer-iframe'+index];
//调用子页面的全局函数
iframe.child(需要往子页面传的值)
}
});
I believe everyone can understand the above code. Here is the code in success. Many people make mistakes in the second step. Child is the global function of your subpage. Don’t forget. Many people have iframe.child is not a function is caused by this reason
two ways
- Subpage code, note here that child must be a global function
function child(data) {
console.log(data)
}
- If it is in layui.use(), you can write like this
layui.use(['form', 'laydate', 'element'], function (obj) {
var form = layui.form, element = layui.element
window.child= function(e) {
let obj = JSON.parse(JSON.stringify(e.data)) //接收一个对象,不转form.val()无法渲染
form.val('layui-detail',obj); //渲染表单
}
})
If it helps you, remember to like it! ! !