1.安装vuecli
2.创建项目
| vue create myProject |
| |
| Manually select features |
| Babel, Router, Vuex, CSS Pre-processors, Linter |
| y |
| with node-sass |
| with standard lint |
| lint on save |
| In dedicated config files |
3.如果没安装sass,需要装sass
| npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ -D |
| npm i -D sass-loader |
4.安装vw
| npm i -D postcss-viewport-units postcss-px-to-viewport postcss-write-svg postcss-aspect-ratio-mini |
5.配置
| module.exports = { |
| css: { |
| loaderOptions: { |
| postcss: { |
| plugins: (loader) => [ |
| require('postcss-aspect-ratio-mini')({}), |
| require('postcss-write-svg')({utf8: false}), |
| require('postcss-px-to-viewport')({ |
| viewportWidth: 750, |
| unitPrecision: 3, |
| viewportUnit: 'vw', |
| fontViewportUnit: 'vw', |
| propList: ['*'], |
| selectorBlackList: [], |
| minPixelValue: 1, |
| mediaQuery: false, |
| replace: true, |
| exclude: [], |
| landscape: false, |
| landscapeUnit: 'vw', |
| landscapeWidth: 568 |
| }), |
| require('postcss-viewport-units')({}) |
| ] |
| } |
| } |
| } |
| } |
6.兼容
| npm i -S viewport-units-buggyfill |
7.main.js中使用
| var hacks = require('viewport-units-buggyfill.hacks'); |
| require('viewport-units-buggyfill').init({ |
| hacks: hacks |
| }); |
8.添加normalize.css
9.引入公共的scss样式
| |
| css: { |
| loaderOptions: { |
| scss: { |
| prependData: `@import "~@/assets/css/common.scss";` |
| } |
| } |
| } |
10.项目中动态引入本地图片,js中使用本地图片
| data() { |
| return { |
| image: require('./img.png) |
| } |
| } |
11.组件样式穿透
使用scoped 后,父组件的样式将不会渗透到子组件中。不过一个子组件的根节点会同时受其父组件的 scoped CSS 和子组件的 scoped CSS 的影响。这样设计是为了让父组件可以从布局的角度出发,调整其子组件根元素的样式
| |
| >>> .vant {} |
| |
| /deep/ .vant {} |
12.使用hbuilderx运行,显示白板
| |
| publicPath: './', |
| 路由使用hash模式 |
| mode: 'hash' |
13.出现横向滚动条
14. 添加axios
15.配送devServer,target一定要写,不然运行会报错upgrade
| devServer: { |
| |
| |
| proxy:{ |
| '/api':{ |
| target: '/', |
| changeOrigin: true, |
| |
| |
| pathRewrite: { |
| '^/api': '/' |
| } |
| } |
| } |
| }, |
16.使用了axios插件后怎么提取公共api.js
| |
| |
| const axios = window.axios; |
17.监听返回按钮,返回页面
| |
| npm i -S vue-awesome-mui |
| |
| import Mui from 'vue-awesome-mui'; |
| |
| Vue.use(Mui); |
| |
| |
| document.addEventListener('plusready', function (a) { |
| let first = ''; |
| window.plus.key.addEventListener('backbutton', function () { |
| |
| const urls = location.hash.split('/')[1]; |
| if (urls === '') { |
| |
| if (new Date().getTime() - first < 3000) { |
| window.plus.runtime.quit(); |
| } else { |
| first = new Date().getTime(); |
| } |
| } else { |
| history.go(-1); |
| } |
| }, false); |
| }); |
| |
| |
| ```js |
| |
| document.addEventListener('plusready', function (a) { |
| let first = ''; |
| window.plus.key.addEventListener('backbutton', function () { |
| |
| const urls = location.hash.split('/')[1]; |
| alert(urls); |
| if (urls === 'index' || urls === 'mine') { |
| |
| if (new Date().getTime() - first < 3000) { |
| window.plus.runtime.quit(); |
| } else { |
| first = new Date().getTime(); |
| } |
| } else { |
| router.go(-1); |
| } |
| }, false); |
| }); |
18.一像素边框
| npm i -D postcss-write-svg |
| |
| postcss: { |
| plugins: (loader) => [ |
| require('postcss-write-svg')({ utf8: false }) |
| ] |
| } |
| |
| @svg 1px-border { |
| height: 2PX; |
| @rect { |
| fill: var(--color, black); |
| width: 100%; |
| height: 50%; |
| } |
| } |
| |
| border-bottom: 1px solid transparent; |
| border-image: svg(1px-border param(--color $navbar-border-color)) 2 2 stretch; |
19.使用hbuilderx打包
本文作者:轻风细雨_林木木
本文链接:https://www.cnblogs.com/linzhifen5/p/16961099.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步