網(wǎng)站首頁 編程語言 正文
web-view
Webview 是一個(gè)基于webkit引擎,可以解析DOM 元素,展示html頁面的控件,它和瀏覽器展示頁面的原理是相同的,所以可以把它當(dāng)做瀏覽器看待。(chrome瀏覽器也是基于webkit引擎開發(fā)的,Mozilla瀏覽器是基于Gecko引擎開發(fā)的)
開發(fā)過小程序的話對這個(gè)標(biāo)簽應(yīng)該比較熟悉,web-view標(biāo)簽與iframe標(biāo)簽類似,可以在我們的頁面中渲染第三方頁面
web-view標(biāo)簽的使用
與iframe標(biāo)簽類似
<iframe src="URL路徑"></iframe>
web-view:
<web-view src="URL路徑"></web-view>
web-view與iframe的區(qū)別
web-view標(biāo)簽?zāi)J(rèn)是占滿屏幕的且不能使用CSS改變樣式(例如在CSS設(shè)置height或者width),甚至web-view的層級是最高的,也就是說不能有元素可以顯示在web-view上
iframe標(biāo)簽則可以通過CSS設(shè)置寬或者高,我們可以將其他元素顯示在iframe標(biāo)簽上,例如(懸浮框組件)
設(shè)置web-view的高度
<template>
<view class="content">
<web-view src="https://www.baidu.com"></web-view>
<view class="header">
<text style="font-size: 40rpx;">標(biāo)題</text>
<u-icon name="share" size="40"></u-icon>
</view>
</view>
</template>
<script>
var wv;
export default {
data() {
return {
}
},
onReady() {
var self = this;
var currentWebview = this.$scope.$getAppWebview();
setTimeout(function() {
let h=720,top=70;
wv = currentWebview.children()[0]
uni.getSystemInfo({//獲取設(shè)備信息
success: function (res) {
h=res.windowHeight-top;
}
});
wv.setStyle({//設(shè)置web-view高度與web-view跟設(shè)備頂部的距離
top:top,
height:h,
})
}, 1000); //如果是頁面初始化調(diào)用時(shí),需要延時(shí)一下
}
}
</script>
<style lang="less" scoped>
.header{
padding: 20rpx;
box-sizing: border-box;
width: 100vw;
height: 140rpx;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-end;
}
</style>
獲取當(dāng)前web-view的URL
<template>
<view class="content">
<web-view src="https://www.baidu.com"></web-view>
<view class="header">
<text style="font-size: 40rpx;">標(biāo)題</text>
<u-icon name="share" size="40" @click="show"></u-icon>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onReady() {
},
methods:{
show(){
var pages = getCurrentPages();
var page = pages[pages.length - 1];
var currentWebview = page.$getAppWebview();
console.log(currentWebview.children()[0].getURL());//獲取當(dāng)前web-view的URL
}
}
}
</script>
<style lang="less" scoped>
.header{
padding: 20rpx;
box-sizing: border-box;
width: 100vw;
height: 140rpx;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-end;
}
</style>
原文鏈接:https://blog.csdn.net/qq_44849271/article/details/125754493
相關(guān)推薦
- 2022-06-01 C#枚舉的高級應(yīng)用_基礎(chǔ)應(yīng)用
- 2022-11-09 Python運(yùn)算符教程之邏輯門詳解_python
- 2022-12-09 解讀opencv中cv2.imread()返回值為None問題及解決_python
- 2024-07-13 SpringBoot入門(解決JDK8不存在問題)
- 2022-05-22 C#開發(fā)Winform實(shí)現(xiàn)窗體間相互傳值_C#教程
- 2022-11-25 Python?Playwright的使用詳解_python
- 2024-03-21 解決SpringBoot項(xiàng)目中的報(bào)錯(cuò):Could not autowire,no beans of
- 2022-12-06 Python中八種數(shù)據(jù)導(dǎo)入方法總結(jié)_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支