提交 27ed3c62 编写于 作者: 雪洛's avatar 雪洛

fix: 修复H5端部分情况下webview组件位置不正确的Bug https://ask.dcloud.net.cn/question/90987

上级 e47003ab
<template> <template>
<uni-web-view v-on="$listeners" /> <uni-web-view v-on="$listeners">
<v-uni-resize-sensor
ref="sensor"
@resize="_resize" />
</uni-web-view>
</template> </template>
<script> <script>
export default { export default {
...@@ -16,24 +20,10 @@ export default { ...@@ -16,24 +20,10 @@ export default {
} }
}, },
mounted () { mounted () {
const {
top,
bottom,
width,
height
} = this.$el.getBoundingClientRect()
this.iframe = document.createElement('iframe') this.iframe = document.createElement('iframe')
this.iframe.style.position = 'absolute'
this.iframe.style.display = 'block'
this.iframe.style.border = 0
this.iframe.style.top = top + 'px'
this.iframe.style.bottom = bottom + 'px'
this.iframe.style.width = width + 'px'
this.iframe.style.height = height + 'px'
this.iframe.src = this.$getRealPath(this.src) this.iframe.src = this.$getRealPath(this.src)
document.body.appendChild(this.iframe) document.body.appendChild(this.iframe)
this._resize()
}, },
activated () { activated () {
this.iframe.style.display = 'block' this.iframe.style.display = 'block'
...@@ -43,6 +33,24 @@ export default { ...@@ -43,6 +33,24 @@ export default {
}, },
beforeDestroy () { beforeDestroy () {
document.body.removeChild(this.iframe) document.body.removeChild(this.iframe)
},
methods: {
_resize () {
const {
top,
bottom,
width,
height
} = this.$el.getBoundingClientRect()
this.iframe.style.position = 'absolute'
this.iframe.style.display = 'block'
this.iframe.style.border = 0
this.iframe.style.top = top + 'px'
this.iframe.style.bottom = bottom + 'px'
this.iframe.style.width = width + 'px'
this.iframe.style.height = height + 'px'
}
} }
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册