improve demo resizing
This commit is contained in:
committed by
Hans Pagel
parent
6fb953dab8
commit
138cd75b3c
@@ -5,7 +5,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<iframe
|
<iframe
|
||||||
v-show="!isLoading"
|
v-show="!isLoading"
|
||||||
v-resize
|
v-resize.quiet
|
||||||
:src="`/demos/${name}?${query}`"
|
:src="`/demos/${name}?${query}`"
|
||||||
style="background-color: transparent;"
|
style="background-color: transparent;"
|
||||||
width="100%"
|
width="100%"
|
||||||
|
|||||||
@@ -23,8 +23,17 @@ export default function (Vue, { head }) {
|
|||||||
Vue.use(PortalVue)
|
Vue.use(PortalVue)
|
||||||
|
|
||||||
Vue.directive('resize', {
|
Vue.directive('resize', {
|
||||||
bind(el, { value = {} }) {
|
bind: (el, { value = {} }) => {
|
||||||
el.addEventListener('load', () => iframeResize(value, el))
|
el.addEventListener('load', () => {
|
||||||
|
iframeResize({
|
||||||
|
...value,
|
||||||
|
messageCallback(messageData) {
|
||||||
|
if (messageData.message === 'resize') {
|
||||||
|
el.iFrameResizer.resize()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}, el)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
unbind(el) {
|
unbind(el) {
|
||||||
el.iFrameResizer.removeListeners()
|
el.iFrameResizer.removeListeners()
|
||||||
|
|||||||
@@ -23,6 +23,26 @@ export default {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
resizeObserver: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.resizeObserver = new window.ResizeObserver(() => {
|
||||||
|
if (window.parentIFrame) {
|
||||||
|
window.parentIFrame.sendMessage('resize')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.resizeObserver.observe(document.body)
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.resizeObserver.unobserve(document.body)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user