废话不多说,直接上代码

参考官方网址:https://uniapp.dcloud.io/component/web-view.html#web-view

参考代码:

<template>
	<view>
		<web-view :webview-styles="webviewStyles" :src="url"></web-view>
	</view>
</template>
<script>
	let wv;
	export default {
		data() {
			return {
				webviewStyles: {
					progress: {
						color: '#4387cb'
					}
				},
				url: ''
			}
		},
		onLoad: function (option) { //option为object类型,会序列化上个页面传递的参数
			this.url = option.url
		},
		onReady() {
			// #ifdef APP-PLUS
			let currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象
			setTimeout(function() {
				wv = currentWebview.children()[0]
				wv.setStyle({
					scalable: true
				})
			}, 1000); //如果是页面初始化调用时,需要延时一下
			// #endif
		}
	}
</script>
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐