js如何实现两个iframe之间传值,下面web建站小编给大家详细介绍一下具体实现代码!
父组件传参
<template>
<view>
<iframe :src="`/demoA?$[params]`"></iframe>
</view>
</template>
<script>
export default {
data() {
return {
params: ''
};
},
mounted() {
const params = {
name: 'web建站',
age: '3',
}
this.params = encodeURIComponent(JSON.stringify(params))
window.addEventListener('message', this.handleMessage)
},
methods: {
handleMessage(event) {
console.log(event, '事件')
if(event.data.status === 'ok') {
console.log(event.data.params, '参数值')
}
}
}
}
</script>
子组件接收参数
<template>
<view>
<p>demoA发来的参数:{{params}}</p>
<button @click="sendMess">发送数据</button>
</view>
</template>
<script>
export default {
data() {
return {
params: ''
};
},
created() {
const params = JSON.parse(decodeURIComponent(window.location.hash.split('?')[1]))
this.params = params
},
methods: {
sendMess() {
window.parent.postMessage({
status: 'ok',
params: {
id: 12
}
}, '*');
}
}
}
</script>
上面是“js如何实现两个iframe之间传值”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3659.html
workflows工作流
一个穿过泥泞雷区的士兵ComfyUI工作流
树上挂着一只表情可爱的香蕉ComfyUI工作流二
一尊白玉佛像ComfyUI工作流
树上挂着一只快乐的小樱桃
一个黄色的海绵宝宝ComfyUI工作流
三阶放大comfyui工作流
一座精致透明的白瓷人物雕塑comfyui工作流
一只可爱的飞鸟ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

如何利用svg做一个有趣的loading动画加载
css3动画loading效果
js实现table表格动态新增行和列表
做一个好玩的时钟翻牌效果
Bootstrap可视化拖放布局
css3做一个风雨雷电天气动态图标
3d文字动画效果
canvas黑洞漩涡(canvas+js)






