Files
ys-app/src/pages/h5-webview/h5-webview.vue
2025-08-15 11:16:08 +08:00

74 lines
1.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<web-view :src="url"></web-view>
</view>
</template>
<script setup>
import { ref,onMounted,getCurrentInstance } from 'vue';
import { onLoad,onReady } from '@dcloudio/uni-app';
const { proxy } = getCurrentInstance();
let windowInfo = ref(null);
let url = ref('');
let title = ref('');
//将要创建的webview对象
let wv;
onLoad(async(opt) => {
// console.log(opt)
url.value = opt.url;
title.value = opt.title;
})
onReady(()=>{
setTimeout(()=>{
uni.setNavigationBarTitle({
title:title.value
})
},2000)
})
onMounted(() => {
uni.getSystemInfo({
success: (res)=> {
windowInfo.value = res;
createWvAndLoadUrl(url.value);
}
});
})
/*创建web-view并加载url*/
const createWvAndLoadUrl=(url)=>{
// #ifdef APP-PLUS
wv = plus.webview.create(url,"webview",{
// plusrequire:"none", //禁止远程网页使用plus的API有些使用mui制作的网页可能会监听plus.key造成关闭页面混乱可以通过这种方式禁止
top: 0,//this.windowInfo.statusBarHeight + 126, //放置在titleNView下方。如果还想在webview上方加个地址栏的什么的可以继续降低TOP值
scalable: true,
height: windowInfo.value.windowHeight - windowInfo.value.statusBarHeight //- 126
})
wv.addEventListener('loading', () => {
plus.nativeUI.showWaiting("loading...",{
width:'110px',
padding:'10px'
})
}, false);
//plus.nativeUI.showWaiting()
wv.addEventListener('loaded', () => {
plus.nativeUI.closeWaiting();
}, false);
//wv.loadURL(url)
let currentWebview = proxy.$scope.$getAppWebview();
currentWebview = wv;
// console.log(wv)
// setTimeout(()=> {
// console.log(wv.getStyle())
// }, 1000);
// #endif
}
</script>
<style scoped>
</style>