App.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <div>
  3. <keep-alive>
  4. <router-view v-if="$route.meta.keepAlive"></router-view>
  5. </keep-alive>
  6. <router-view v-if="!$route.meta.keepAlive"></router-view>
  7. </div>
  8. </template>
  9. <script>
  10. import $ from 'jquery'
  11. export default {
  12. name: "app",
  13. created() { },
  14. mounted() {
  15. let width=$("body").width();
  16. console.log(width)
  17. if(width>=1200){
  18. let fontsize=width/1920*40;//fontsize为当前屏幕的基数字体,相对于设计稿计算得到的。
  19. $("html").css("font-size",`${fontsize}px`)
  20. }
  21. if(width<=750){
  22. let fontsize=width/400*40;
  23. $("html").css("font-size",`${fontsize}px`)
  24. }
  25. //当加载页面的时候设置生效
  26. window.onresize = () => {
  27. return (() => {
  28. let width=$("body").width();
  29. if(width>=1200){
  30. let fontsize=width/1920*40;
  31. $("html").css("font-size",`${fontsize}px`)
  32. }
  33. if(width<=750){
  34. let fontsize=width/400*40;
  35. $("html").css("font-size",`${fontsize}px`)
  36. }
  37. })()
  38. }
  39. }
  40. };
  41. </script>