(1)子頁面調用父頁面的方法
父頁面
created() {
var _this = this
//這里可放到全局,提供給子 iframe 調用
window.addTab = function(obj){
return TabUtil().addTab(obj)
}
}
子頁面調用
window.parent.addTab(obj)
(2)父頁面調用子頁面的方法
子頁面
created() {
var _this = this
//這里可放到全局
window.resizeWindow = function() {
return _this.resizeWindow()
}
},
methods: {
//窗口變化處理
resizeWindow () {
console.log('頁面在變化')
}
}
父頁面調用
var iframe_home = document.querySelector('#iframe_home')
iframe_home.contentWindow.resizeWindow()
iframe_home : iframe標簽id
(3)子頁面獲取父頁面對象
var parent = window.parent.document.querySelector('#mask-div')
(4)父頁面獲取子頁面對象
var iframe = document.querySelector('#iframe_home')
var children = iframe.contentWindow.document.querySelector('#children')