webview.uvue 826 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <view class="page-container">
  3. <web-view :src="url" class="webview"></web-view>
  4. </view>
  5. </template>
  6. <script setup lang="uts">
  7. import { ref, onMounted } from 'vue'
  8. const url = ref<string>('')
  9. onMounted(() => {
  10. const pages = getCurrentPages()
  11. const currentPage = pages[pages.length - 1]
  12. const options = currentPage.options
  13. let targetUrl: string = ''
  14. if (options != null) {
  15. const urlParam = options['url']
  16. if (urlParam != null) {
  17. const urlStr: string = urlParam.toString()
  18. const decodedUrl: string | null = decodeURIComponent(urlStr)
  19. if (decodedUrl != null) {
  20. targetUrl = decodedUrl
  21. }
  22. }
  23. }
  24. url.value = targetUrl
  25. })
  26. </script>
  27. <style lang="scss">
  28. .page-container {
  29. flex: 1;
  30. width: 100%;
  31. height: 100%;
  32. }
  33. .webview {
  34. width: 100%;
  35. height: 100%;
  36. }
  37. </style>