index.vue 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div class="myIframe" v-loading="loadLoading" ref="myIframe">
  3. <iframe ref="iframe" :src="src" v-bind="$attrs" height="100%" width="100%"></iframe>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. components: {},
  9. props: {
  10. src:{
  11. default:''
  12. }
  13. },
  14. data() {
  15. return {
  16. loadLoading:false
  17. };
  18. },
  19. watch: {
  20. src(){
  21. this.loadIframe()
  22. }
  23. },
  24. computed: {},
  25. created() {},
  26. mounted() {
  27. this.loadIframe()
  28. },
  29. methods: {
  30. loadIframe(){
  31. if(!this.src){
  32. return
  33. }
  34. var that = this
  35. this.$nextTick(()=>{
  36. var a = that.$refs.iframe
  37. a.onload = function() {
  38. that.loadLoading = false
  39. };
  40. if(a.contentDocument.readyState == 'complete'){
  41. that.loadLoading = false
  42. }
  43. })
  44. }
  45. },
  46. };
  47. </script>
  48. <style lang="scss" scoped>
  49. .myIframe{
  50. width: 100%;
  51. height: 100%;
  52. }
  53. </style>