content.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <iframe class="report-content" :style="{height: contentHeight + 'px'}"></iframe>
  3. </template>
  4. <style lang="scss" scoped>
  5. .report-content {
  6. background: 0 0;
  7. border: 0;
  8. float: none;
  9. margin: 6px 0;
  10. max-width: none;
  11. outline: 0;
  12. padding: 0;
  13. position: static;
  14. width: 100%;
  15. }
  16. </style>
  17. <script>
  18. /**
  19. * 预览内容
  20. */
  21. export default {
  22. name: 'ReportContent',
  23. props: {
  24. content: {
  25. default: ''
  26. },
  27. },
  28. data() {
  29. return {
  30. contentHeight: 50,
  31. }
  32. },
  33. mounted() {
  34. this.setContent(this.content);
  35. },
  36. watch: {
  37. content(val) {
  38. this.setContent(val);
  39. }
  40. },
  41. methods: {
  42. setContent(val) {
  43. if (!this.$el.contentWindow) {
  44. return;
  45. }
  46. let $d = this.$el.contentWindow.document;
  47. $A("body", $d).html('<link type="text/css" rel="stylesheet" href="' + window.location.origin + '/js/build/skins/ui/oxide/content.min.css"><style>html,body{padding:0;margin:0}</style><div id="content">' + val + '</div>');
  48. this.$nextTick(() => {
  49. this.contentHeight = $d.getElementById("content").scrollHeight;
  50. });
  51. }
  52. }
  53. }
  54. </script>