提交 41148982 编写于 作者: fxy060608's avatar fxy060608

fix(h5): web-view 组件重复加载(http://ask.dcloud.net.cn/question/71466)

上级 b27aac4d
<template>
<uni-web-view>
<iframe
:src="$getRealPath(src)"
frameborder="0"
width="100%"
height="100%" />
</uni-web-view>
</template>
<script>
export default {
name: 'WebView',
props: {
src: {
type: String,
default: ''
<template>
<uni-web-view />
</template>
<script>
export default {
name: 'WebView',
props: {
src: {
type: String,
default: ''
}
},
watch: {
src (val, oldVal) {
this.iframe && (this.iframe.src = this.$getRealPath(this.src))
}
}
}
</script>
<style>
uni-web-view iframe {
position: absolute;
}
},
mounted () {
const {
top,
bottom,
width,
height
} = this.$el.getBoundingClientRect()
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)
document.body.appendChild(this.iframe)
},
activated () {
this.iframe.style.display = 'block'
},
deactivated () {
this.iframe.style.display = 'none'
},
beforeDestroy () {
document.body.removeChild(this.iframe)
}
}
</script>
<style>
uni-web-view {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册