# vue3.x_vw_layout **Repository Path**: yzfgits/vue3.x_vw_layout ## Basic Information - **Project Name**: vue3.x_vw_layout - **Description**: vw布局实现移动端适配,项目使用 vue-cli@3.x 搭建 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 3 - **Created**: 2018-08-18 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # vuecli3vw # 总体思路 - 你可以参考此文档完成`vw`布局适配移动端,适用于`vuecli3.x`搭建的项目 - 此文档是带领你完成一项具体任务,而不是教你如何编程 ## 1. 使用`vuecli3.x`搭建项目 ## 2. 在项目根目录的`.postcssrc.js`文件中增加配置项 ## 3. 使用`npm`下载相关包 ## 4. 在`index.html`引入js插件并使用该插件 ## 5. 在`App.vue`组件中尝试使用vw布局 ## 6. 运行项目,验证是否成功 # 操作流程 ### 1. 使用`vuecli3.x`创建项目 ``` vue create vuecli3vw ``` - 具体操作步骤参考一下gif图片,此项目勾选了 vue-router, vuex, babel  ``` 需要注意的是: 询问配置 PostCSS 时需要选择的是 `In dedicated config files` 在专用配置文件中 ? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? (Use arrow keys) > In dedicated config files In package.json ``` ### 2. 在项目根目录的`.postcssrc.js`文件中增加配置项 - `.postcssrc.js`全部内容 ``` //https://github.com/michael-ciniawsky/postcss-load-config // module.exports = { // plugins: { // autoprefixer: {} // } // } module.exports = { "plugins": { "postcss-import": {}, "postcss-url": {}, "postcss-aspect-ratio-mini": {}, "postcss-write-svg": { utf8: false }, "postcss-cssnext": {}, "postcss-px-to-viewport": { viewportWidth: 750, // 视窗的宽度,对应的是我们设计稿的宽度,一般是750 viewportHeight: 1334, // 视窗的高度,根据750设备的宽度来指定,一般指定1334,也可以不配置 unitPrecision: 3, // 指定`px`转换为视窗单位值的小数位数(很多时候无法整除) viewportUnit: 'vw', // 指定需要转换成的视窗单位,建议使用vw selectorBlackList: ['.ignore', '.hairlines'], // 指定不转换为视窗单位的类,可以自定义,可以无限添加,建议定义一至两个通用的类名 minPixelValue: 1, // 小于或等于`1px`不转换为视窗单位,你也可以设置为你想要的值 mediaQuery: false // 允许在媒体查询中转换`px` }, "postcss-viewport-units":{}, "cssnano": { preset: "advanced", autoprefixer: false, "postcss-zindex": false }, } } ``` ### 3. 使用`npm`下载相关包 ``` npm i cssnano postcss-aspect-ratio-mini postcss-cssnext postcss-px-to-viewport postcss-viewport-units postcss-write-svg -S npm i cssnano-preset-advanced -D npm i postcss-import postcss-url autoprefixer -D ``` ### 4. 在`index.html`引入js插件并使用该插件 ```