App.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <router-view/>
  3. </template>
  4. <script setup lang="ts">
  5. import { onMounted, onUnmounted } from 'vue'
  6. import { useRoute, useRouter } from 'vue-router'
  7. import { throttle } from './utils/throttle'
  8. const route = useRoute()
  9. const router = useRouter()
  10. onMounted(() => {
  11. setRem()
  12. // 计算屏幕宽度决定pc还是移动端
  13. throttle(resizeChange(), 200)
  14. // window.addEventListener('resize', resizeChange, false)
  15. window.addEventListener('resize', setRem, false)
  16. })
  17. const resizeChange = () => {
  18. // 移动端页面
  19. if (document.body.clientWidth <= 750) {
  20. if (route.path.indexOf('/p_') !== -1) {
  21. router.replace({ path: route.path.replace('/p_', '/m_') })
  22. }
  23. } else {
  24. // pc端页面
  25. if (route.path.indexOf('/m_') !== -1) {
  26. router.replace({ path: route.path.replace('/m_', '/p_') })
  27. }
  28. }
  29. }
  30. const setRem = () => {
  31. const pWidth = 750
  32. const pre = 100
  33. const windowWidth = document.documentElement.clientWidth
  34. document.documentElement.style.fontSize = (windowWidth / pWidth) * pre + 'px'
  35. // console.log('rem适配:', windowWidth, (windowWidth / pWidth) * pre + 'px');
  36. }
  37. onUnmounted(() => {
  38. window.removeEventListener('resize', resizeChange, false)
  39. window.removeEventListener('resize', setRem, false)
  40. })
  41. </script>
  42. <style scoped lang="scss">
  43. </style>
  44. <style lang="scss">
  45. .van-button.van-button--normal {
  46. padding: 5px 15px;
  47. width: auto;
  48. height: auto;
  49. }
  50. /*谷歌*/
  51. input::-webkit-outer-spin-button,
  52. input::-webkit-inner-spin-button {
  53. -webkit-appearance: none;
  54. }
  55. /*火狐*/
  56. input[type="number"] {
  57. -moz-appearance: textfield;
  58. }
  59. </style>
  60. <style>
  61. .mob-wrap{
  62. max-width: 750px;
  63. margin: 0 auto;
  64. background-color: #fff;
  65. min-height: 90vh;
  66. /* height: 100%; */
  67. box-sizing: border-box;
  68. /* padding: 15px; */
  69. }
  70. .wrap-outer{
  71. background-image: linear-gradient(to bottom left, #ED8C0F, #EF6158, #C85384, #875892, #49557F, #2F4858 );
  72. /* height: 100%; */
  73. max-height: 100vh;
  74. overflow: auto;
  75. box-sizing: border-box;
  76. }
  77. </style>