vuejs&electron-vue----朝花夕拾.

————僅以此文紀錄個人運用vuejs開闢項目對一些需求的處置懲罰要領,不定期更新…

加載favicon.ico圖標

//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')
})

全局增加sass變量聲明

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')
  }

指定途徑或文件範例去掉eslint校驗

//.eslintignore

/build/
/config/
/dist/
/*.js
/test/unit/coverage/
/src/plugins

修正v-html內容款式

//template

 <div class="agreement"  ref="html" v-html="agreement.contractContent"></div>

//script

  updated () {
    this.$refs.html.childNodes.forEach(element => {
      element.style.fontSize = '0.3rem'
    })
  }

過濾input展現筆墨

//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'
    }
  }

vue-router導航守御及路由重定向同時運用時,重定向需放在導航守御背面

//script

   routes: [
        {
            path: '/',
            name: 'Home',
            component: Home;
            },
            beforeEnter: (to, from, next) => {
                ...dosomething()
                next()
            },
            redirect: { path: 'anotherPage' },
            children: []
            }
         ]
    

臨盆環境去除console及debugger

/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兼容低版本瀏覽器

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(...);

electron-vue運用electron-builder指定打包32位。

//package.json

    "win": {
      "icon": "build/icons/icon.ico",
      "target": [
        {
          "target": "nsis",
          "arch": [
            "ia32"
          ]
        }
      ]
    },

electron-vue開闢環境跨域代辦設置

//.electron-vue/dev-runner.js

function startRenderer(){
...
        proxy: {
          '/api': {
            target: 'http://192.168.74.222:6019',
            // secure: false,  // 假如是https接口,須要設置這個參數
            changeOrigin: true, // 假如接口跨域,須要舉行這個參數設置
            pathRewrite: {
              '^/api': ''
            }
          }
        }
        ...
}

經由過程BrowserWindow新窗口翻開項目內頁面

      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
      })
    原文作者:菠蘿油王子
    原文地址: https://segmentfault.com/a/1190000014771866
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞