router.map({ '/': { component: Home }, '/products': { component: Products, subRoutes: { '/:product': { name: 'product', component: Detail } } } });
import Vue from 'vue'; import VueRouter from 'vue-router'; import Home from './components/home/home.vue'; import Products from './components/products/products.vue'; import Detail from './components/products/detail.vue'; Vue.use(VueRouter); let router = new VueRouter(); router.map({ '/': { component: Home }, '/products': { component: Products, subRoutes: { '/:product': { name: 'product', component: Detail } } } }); export default router;
每个操作都是状态,比如打开子菜单,进入某个路由。
把需要的数据(当前状态)保存下来。
const SET_PRODUCT = 'SET_PRODUCT'; let state = { product: {}, }; let mutations = { [SET_PRODUCT] (state, productName = '') { state.product = oms.find(it => Object.is(it.nickname, productName)); } }; export default new Vuex.Store({ state: { product: {} }, mutations: { [SET_PRODUCT] (state, productName = '') { state.product = oms.find(it => Object.is(it.nickname, productName)); } } });
import Vue from 'vue'; import Vuex from 'vuex'; import {oms} from '../data/tz-data'; Vue.use(Vuex); const SET_PRODUCT = 'SET_PRODUCT'; let state = { product: {}, }; let mutations = { [SET_PRODUCT] (state, productName = '') { state.product = oms.find(it => Object.is(it.nickname, productName)); } }; export default new Vuex.Store({ state: { product: {} }, mutations: { [SET_PRODUCT] (state, productName = '') { state.product = oms.find(it => Object.is(it.nickname, productName)); } } });
webpack.config.babel.js
... module: { loaders: [ { test: /\.js?$/, exclude: /node_modules/, loader: 'babel', query: { presets: ['es2015', 'stage-0'], plugins: ['transform-runtime'] } } ... ] }, ...
moduleA.js
module.exports = function( value ){ return value * 2; }
moduleB.js
var multiplyBy2 = require('./moduleA'); var result = multiplyBy2( 4 );
moduleA.js
define('myModule', ['jquery'], function($) { $('body').text('hello world'); });
moduleB.js
require(['myModule'], function(myModule) {});
import 'mocha'; import {expect} from 'chat'; import Util from './util'; describe(`#isChinese()`, () => { it(`should be Chinese`, () => { expect(Util.isChinese(`摩卡摩卡摩卡摩卡摩卡`)).to.equal(true); }); it(`should not be Chinese`, () => { expect(Util.isChinese()).to.equal(false); expect(Util.isChinese(`mocha`)).to.equal(false); expect(Util.isChinese(` mocha `)).to.equal(false); expect(Util.isChinese(`摩卡m`)).to.equal(false); expect(Util.isChinese(`m摩卡`)).to.equal(false); expect(Util.isChinese(` 摩卡`)).to.equal(false); }); });
谢谢~( •̀ ω •́ )y