index.jsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { useMain } from '@cip/hooks/use-main'
  2. import './index.less'
  3. import { computed, onMounted } from 'vue'
  4. import { isObject } from '@cip/utils/util'
  5. import { useRouter } from 'vue-router'
  6. export default {
  7. props: {
  8. subPath: String,
  9. baseUrl: String,
  10. query: Object
  11. },
  12. setup (props) {
  13. const { setCurrentTitle } = useMain()
  14. const router = useRouter()
  15. const src = computed(() => {
  16. return `${props.baseUrl}/${props.subPath}?`
  17. })
  18. onMounted(() => {
  19. window.addEventListener('message', (e) => {
  20. const { data } = e
  21. if (isObject(data)) {
  22. let { type, fullPath } = data
  23. if (type === 'changeUrl') {
  24. fullPath = decodeURI(fullPath.substr(1))
  25. if (fullPath !== props.subPath) {
  26. console.log(fullPath)
  27. router.push({ params: { subPath: fullPath } })
  28. }
  29. }
  30. }
  31. })
  32. })
  33. return () => <iframe class={'cip-iframe-container'} frameBorder={0} src={src.value}></iframe>
  34. }
  35. }