index.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div class="auto-main">
  3. <Component :is="comIs"/>
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import {
  8. defineComponent,
  9. ref,
  10. nextTick,
  11. onMounted,
  12. watch,
  13. computed,
  14. ComponentInternalInstance,
  15. reactive,
  16. toRefs,
  17. getCurrentInstance
  18. } from 'vue'
  19. import PcCom from '../pc/index.vue'
  20. import ScreenCom from '../screen/index.vue'
  21. export default defineComponent({
  22. name: 'App',
  23. components: {},
  24. setup() {
  25. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
  26. const state = reactive({
  27. comIs: PcCom
  28. });
  29. onMounted(() => {
  30. if (document.body.clientWidth <= 2000) {
  31. state.comIs = PcCom
  32. } else {
  33. state.comIs = ScreenCom
  34. }
  35. window.onresize = (e) => {
  36. if (e?.target?.innerWidth <= 2000) {
  37. state.comIs = PcCom
  38. } else {
  39. state.comIs = ScreenCom
  40. }
  41. }
  42. })
  43. return {
  44. ...toRefs(state),
  45. }
  46. }
  47. })
  48. </script>
  49. <style lang="scss" scoped>
  50. </style>