【快应用】webview接口打开网页,网页会被自动放大,如何适配手机大小

【现象描述】

通过webview接口打开网页,网页会被自动放大,问题代码如下:

webview.loadUrl({

url: 'https://cdn.langqing.club/jQuery/index.html',

allowthirdpartycookies: true

})

 

【问题分析】

原因在于快应用加载器没有对网页的比例和屏幕的宽度做适配,默认显示网页实际的宽度,没有将网页内容全部显示在屏幕宽度内。

 

【解决方法】

可以通过web组件加载网页,并设置overviewmodeinload属性为true规避此问题。代码如下:

<template>

<div class="container">

<web src="https://cdn.langqing.club/jQuery/index.html" overviewmodeinload="true"></web>

</div>

</template>

<style>

.container {

flex-direction: column;

}

</style>

<script>

module.exports = {

data: {

},

onInit() {

this.$page.setTitleBar({

text: 'menu',

textColor: '#ffffff',

backgroundColor: '#007DFF',

backgroundOpacity: 0.5,

menu: true

});

},

}

</script>

 

欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh

{{o.name}}
{{m.name}}

猜你喜欢

转载自my.oschina.net/u/4478396/blog/5566006