1、新建一个vue项目,自行选择

  1. vue create ***

2、安装rem

  1. yarn add lib-flexible postcss-pxtorem

3、配置postcss.config.js文件

  1. module.exports = {
  2. plugins: {
  3. autoprefixer: {},
  4. 'postcss-pxtorem': {
  5. rootValue: 37.5,
  6. propList: ['*']
  7. }
  8. }
  9. }
  1. public/index.html
  2. 注释这一行(最新版本不需要注释掉这行)
  3. <!-- <meta name="viewport" content="width=device-width,initial-scale=1.0"> -->

4、在main.js中引入

  1. import 'lib-flexible/flexible'

5、rem是为移动端而生的要在pc和ipad上跑,一定要在App.vue文件中加

  1. <template>
  2. <div id="app">
  3. <router-view></router-view>
  4. </div>
  5. </template>
  6. <style lang="less">
  7. #app {
  8. width:10rem;
  9. height: 100px;
  10. margin-left:auto;
  11. margin-right:auto;
  12. background-color: pink;
  13. }
  14. </style>

6、引入reset.css样式重置

  1. import '@/assets/css/reset.css'
  2. html, body, div, span, applet, object, iframe,
  3. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  4. a, abbr, acronym, address, big, cite, code,
  5. del, dfn, em, img, ins, kbd, q, s, samp,
  6. small, strike, strong, sub, sup, tt, var,
  7. b, u, i, center,
  8. dl, dt, dd, ol, ul, li,
  9. fieldset, form, label, legend,
  10. table, caption, tbody, tfoot, thead, tr, th, td,
  11. article, aside, canvas, details, embed,
  12. figure, figcaption, footer, header, hgroup,
  13. menu, nav, output, ruby, section, summary,
  14. time, mark, audio, video {
  15. margin: 0;
  16. padding: 0;
  17. border: 0;
  18. font-size: 100%;
  19. font: inherit;
  20. vertical-align: baseline;
  21. }
  22. /* HTML5 display-role reset for older browsers */
  23. article, aside, details, figcaption, figure,
  24. footer, header, hgroup, menu, nav, section {
  25. display: block;
  26. }
  27. body {
  28. line-height: 1;
  29. }
  30. ol, ul {
  31. list-style: none;
  32. }
  33. blockquote, q {
  34. quotes: none;
  35. }
  36. blockquote:before, blockquote:after,
  37. q:before, q:after {
  38. content: '';
  39. content: none;
  40. }
  41. table {
  42. border-collapse: collapse;
  43. border-spacing: 0;
  44. }