preview.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <web-view :src="webSrc"/>
  3. </template>
  4. <script setup>
  5. import {ref, onMounted, getCurrentInstance} from "vue";
  6. import {onLoad} from '@dcloudio/uni-app'
  7. //初始变量
  8. let wv;
  9. const instance = getCurrentInstance().proxy
  10. const webSrc = ref('');
  11. onLoad((option) => {
  12. if (option.url) {
  13. webSrc.value = '/hybrid/html/pdf/web/viewer.html?file= ' + decodeURIComponent(option.url);
  14. }
  15. })
  16. //渲染完成
  17. onMounted(() => {
  18. // #ifdef APP-PLUS
  19. let currentWebview = instance.$scope.$getAppWebview()
  20. //如果是页面初始化调用时,需要延时一下
  21. setTimeout(function() {
  22. wv = currentWebview.children()[0]
  23. wv.setStyle({scalable:true})
  24. // #ifdef APP-PLUS
  25. //ios 禁用缓存,测试生效!!
  26. let cache1 = plus.ios.newObject('NSURLCache');
  27. let cache = plus.ios.invoke(cache1, 'sharedURLCache');
  28. plus.ios.invoke(cache, 'removeAllCachedResponses');
  29. plus.ios.invoke(cache, 'setDiskCapacity:', 0);
  30. plus.ios.invoke(cache, 'setMemoryCapacity:', 0);
  31. //安卓端缓存清理。
  32. plus.cache.clear();
  33. // #endif
  34. }, 1000);
  35. // #endif
  36. })
  37. </script>
  38. <style lang="scss">
  39. page {
  40. height: auto;
  41. }
  42. </style>