界之边缘的轮回 2019-06-27
————仅以此文记录个人使用vuejs开发项目对一些需求的处理方法,不定期更新...
//index.html
<link href="./favicon.ico" rel="icon" type="image/x-icon" />
// build/webpack.dev.conf.js
new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html', inject: true, favicon: path.resolve('favicon.ico') })
npm install -D sass-resources-loader
//build/utils.js
return { css: generateLoaders(), postcss: generateLoaders(), less: generateLoaders('less'), sass: generateLoaders('sass', { indentedSyntax: true }), scss: generateLoaders('sass').concat( { loader: 'sass-resources-loader', options: { resources: path.resolve(__dirname, '../src/styles/variables.scss') } } ), stylus: generateLoaders('stylus'), styl: generateLoaders('stylus') }
//.eslintignore
/build/ /config/ /dist/ /*.js /test/unit/coverage/ /src/plugins
//template
<div class="agreement" ref="html" v-html="agreement.contractContent"></div>
//script
updated () { this.$refs.html.childNodes.forEach(element => { element.style.fontSize = '0.3rem' }) }
//template
<input type = "text" v-bind:value="kilometers | changeToMoney">
//script
filters:{ changeToMoney:function(value){ return "$"+value; } }
//template
<transition :name="transitionName"> <keep-alive> <router-view class="child-view"></router-view> </keep-alive> </transition>
//script
data () { return { transitionName: 'slide-left' } }, // 监听路由的路径,可以通过不同的路径去选择不同的切换效果 watch: { '$route' (to, from) { console.log('现在路由:', to.path.split('/')[1], '来自路由:', from.path.split('/')[1], '现在的动画:', this.transitionName) const toDepth = to.path.split('/').length const fromDepth = from.path.split('/').length this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left' } }
//script
routes: [ { path: '/', name: 'Home', component: Home; }, beforeEnter: (to, from, next) => { ...dosomething() next() }, redirect: { path: 'anotherPage' }, children: [] } ]
/build/webpack.config.prod.conf.js
new UglifyJsPlugin({ uglifyOptions: { compress: { warnings: false, drop_debugger: true, //add drop_console: true //add } }, sourceMap: config.build.productionSourceMap, parallel: true }),
/utils.js
ExtractTextPlugin.extract({ use: loaders, publicPath:'../../', //add fallback: 'vue-style-loader' })
axios是基于Promise的,如果需要兼容低版本浏览器如ie11及以下,需要引入polyfill。
Polyfill 推荐使用 es6-promise
To install:
npm install es6-promise-polyfill
To use:
var Promise = require('es6-promise-polyfill').Promise; var promise = new Promise(...);
//package.json
"win": { "icon": "build/icons/icon.ico", "target": [ { "target": "nsis", "arch": [ "ia32" ] } ] },
//.electron-vue/dev-runner.js
function startRenderer(){ ... proxy: { '/api': { target: 'http://192.168.74.222:6019', // secure: false, // 如果是https接口,需要配置这个参数 changeOrigin: true, // 如果接口跨域,需要进行这个参数配置 pathRewrite: { '^/api': '' } } } ... }
const BrowserWindow = require('electron').remote.BrowserWindow const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080/#/new` : `file://${__dirname}/index.html#new` let newWindow = new BrowserWindow({ height: 600, width: 800 }) newWindow.loadURL(winURL) newWindow.on('closed', () => { newWindow = null })