Giter Site home page Giter Site logo

nuxt-demo's Introduction

Nuxt 项目配置

SCSS

npm i node-sass sass-loader@10 scss-loader --save-dev 引用全局scss变量

https://github.com/nuxt-community/style-resources-module

npm i @nuxtjs/style-resources -D

edit nuxt.config.js

export default {
  buildModules: ['@nuxtjs/style-resources'],
  styleResources: {
    scss: [
      './assets/vars/*.scss'
      ]
  }
}

Vuex持久化存储(vuex-persistedstate)

https://www.npmjs.com/package/vuex-persistedstate

npm install vuex-persistedstate --save

添加插件 add plugins/vuex-persistedstate.js

  import createPersistedState from 'vuex-persistedstate'

  export default (context) => {
    createPersistedState({
      // 默认为localStorage
      storage: window.sessionStorage,
      reducer(obj) {
        const { count, token } = obj
        return { count, token }
      }
    })(context.store)
  }

并在nuxt.config.js

  export default {
    plugins: [{ src: '@/plugins/vuex-persistedstate', ssr: false }]
  }

添加忽略文件

​ 默认规则下,page目录下文件会添加到页面栈内,将components文件夹忽略

add .nuxtignore  
	pages/**/components/

Axios

https://axios.nuxtjs.org/

npm i @nuxtjs/axios --save

edit nuxt.config.js

  export default {
    axios: {
      baseURL: 'http://api-eadmin-dev.haioupai.com',
      progress: true
    },
  }

add plugins/axios.js

  export default function ({ $axios, redirect }) {
    $axios.onRequest(config => {
      console.log('Making request to ', config.url)
    })

​	$axios.onError(error => {
 	 const code = parseInt(error.response && error.response.status)
  	 if (code === 400) {
​    	redirect('/400')
 	 }
​	})

  }

Element UI 按需引入

npm install babel-plugin-component --save-dev

add plugins/element-ui.js

import Vue from 'vue'
import {
  Button,
}

Vue.use(Button)

并在nuxt.config.js

export default {
    plugins: [
      { src: '@/plugins/element-ui', ssr: true },
    ],
    build: {
      // 外联css
      extractCSS: { allChunks: true },
      // transpile: [/^element-ui/],
      // 按需引入
      babel: {
        plugins: [
          ['component',
            {
              libraryName: 'element-ui',
              styleLibraryName: 'theme-chalk'
            }
          ]
        ]
      }
    }
  }

nuxt-demo's People

Contributors

zz026 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.