12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <template>
- <web-view :src="webSrc"/>
- </template>
- <script setup>
- import {ref, onMounted, getCurrentInstance} from "vue";
- import {onLoad} from '@dcloudio/uni-app'
- //初始变量
- let wv;
- const instance = getCurrentInstance().proxy
- const webSrc = ref('');
- onLoad((option) => {
- if (option.url) {
- webSrc.value = '/hybrid/html/pdf/web/viewer.html?file= ' + decodeURIComponent(option.url);
- }
- })
- //渲染完成
- onMounted(() => {
- setWebViewStyle()
- })
- //设置样式
- const setWebViewStyle = async () => {
- // #ifdef APP-PLUS
- await initWebview()
- // #endif
- }
- //初始化webview
- const initWebview = async () => {
- return new Promise((resolve) => {
- let currentWebview = instance.$scope.$getAppWebview()
- //如果是页面初始化调用时,需要延时一下
- setTimeout(function() {
- wv = currentWebview.children()[0]
- wv.setStyle({scalable:true})
- // #ifdef APP-PLUS
- //ios 禁用缓存,测试生效!!
- let cache1 = plus.ios.newObject('NSURLCache');
- let cache = plus.ios.invoke(cache1, 'sharedURLCache');
- plus.ios.invoke(cache, 'removeAllCachedResponses');
- plus.ios.invoke(cache, 'setDiskCapacity:', 0);
- plus.ios.invoke(cache, 'setMemoryCapacity:', 0);
- //安卓端缓存清理。
- plus.cache.clear();
- // #endif
- resolve(true)
- }, 1000);
- })
- }
- </script>
- <style lang="scss">
- page {
- height: auto;
- }
- </style>
|