Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

不同源iframe中怎么调取vue methods中的方法?

父页面 和子页面 是在bai一个域下, 也是就是 协议 主机名 端口号是一致的,在iframe中可以直接调用

mounted()?{
????window.init?=?this.init
},
methods?:?{
????init()?{?console.log('test')}
}
//?子页面直接调用
parent.init()

不同源的怎么调用,我对这块一无所知,求解答。
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

当然 同源直接访问是可以的。
不过还是推荐window.postMessage,iframe下就是iframe.contentWindow;必须要子页面监听了相应的事件,你通过postMessage去触发它,而不能直接跨域操作。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...