在這以前,你須要肯定已經具有環境:node.js;vue.js;vue.cli;webpack;css
目錄:vue
1.使用vue-cli 和 airyland/vux2 構建vuxnode
2.如何在vue-cli中使用lesswebpack
1、使用vue-cli 和 airyland/vux2 構建vuxweb
# install vue-cli
npm install -g vue-cli
# init a webpack project with vuxjs/template
vue init airyland/vux2 projectName
cd projectName
# or cnpm install
npm install
npm run dev
輸入 http://localhost:8123(端口在config裏能夠修改)便可查看vue-router
注:咱們下載的官網模板,路由是以常量的形式寫在了main.js中,這裏咱們恢復到router/index.js中去vue-cli
main.jsnpm
import Vue from 'vue' import FastClick from 'fastclick' import router from './router' import App from './App' // import Home from './components/HelloFromVux' // Vue.use(VueRouter) // const routes = [{ // path: '/', // component: Home // }] // const router = new VueRouter({ // routes // }) FastClick.attach(document.body) Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ router, render: h => h(App) }).$mount('#app-box')
router/index.jsapp
import Vue from 'vue' import Router from 'vue-router' import Hello from '@/components/HelloFromVux' Vue.use(Router) export default new Router({ mode: 'history', //history模式能夠去掉url中的 '#' routes: [ { path: '/', name: 'Hello', component: Hello } ] })
2、如何在vue-cli中使用lessless
首先安裝less
npm install less less-loader --save-dev
其次在build/webpack.base.conf.js中加入一則less的rule
module.exports = { // 此處省略無數行,已有的的其餘的內容 module: { rules: [ // 此處省略無數行,已有的的其餘的規則 { test: /\.less$/, loader: "style-loader!css-loader!less-loader", } ] } }
搞定