From 9921ed185929f8922911118f84dc3ca052cc8781 Mon Sep 17 00:00:00 2001 From: tangjinzhou Date: Fri, 3 Nov 2017 12:04:39 +0800 Subject: [PATCH] vue router --- .babelrc | 3 +- .eslintrc | 1 + components/button/demo/basic.vue | 17 ++++++ components/button/demo/button.vue | 96 +++++++++++++++++++++++++++++++ components/index.js | 7 --- examples/button.vue | 2 +- examples/index.html | 4 +- examples/index.js | 36 ++++-------- examples/routes.js | 11 ++++ package.json | 3 + webpack.config.js | 1 + 11 files changed, 147 insertions(+), 34 deletions(-) create mode 100644 components/button/demo/basic.vue create mode 100644 components/button/demo/button.vue create mode 100644 examples/routes.js diff --git a/.babelrc b/.babelrc index 17e739933..e2f43ba0f 100644 --- a/.babelrc +++ b/.babelrc @@ -2,6 +2,7 @@ "presets": ["env"], "plugins": [ "transform-vue-jsx", - "transform-object-rest-spread" + "transform-object-rest-spread", + "syntax-dynamic-import" ] } diff --git a/.eslintrc b/.eslintrc index acd24c6e4..acc3aeff6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,4 +1,5 @@ { + "parser": "babel-eslint", "extends": ["plugin:vue-libs/recommended"], // ,"plugin:vue-libs/recommended" "rules": { "comma-dangle": [2, "always-multiline"], diff --git a/components/button/demo/basic.vue b/components/button/demo/basic.vue new file mode 100644 index 000000000..065e842df --- /dev/null +++ b/components/button/demo/basic.vue @@ -0,0 +1,17 @@ + + diff --git a/components/button/demo/button.vue b/components/button/demo/button.vue new file mode 100644 index 000000000..a1545a162 --- /dev/null +++ b/components/button/demo/button.vue @@ -0,0 +1,96 @@ + + diff --git a/components/index.js b/components/index.js index c86f04856..e69195d65 100644 --- a/components/index.js +++ b/components/index.js @@ -1,10 +1,3 @@ -import './button/style' -import './checkbox/style' -import './icon/style' -import './radio/style' -import './grid/style' -import './rate/style' - export { default as Button } from './button' export { default as Checkbox } from './checkbox' diff --git a/examples/button.vue b/examples/button.vue index f3c007fc7..edfc45114 100644 --- a/examples/button.vue +++ b/examples/button.vue @@ -73,7 +73,7 @@ diff --git a/examples/index.js b/examples/index.js index 39fea342b..fee4bf6c9 100644 --- a/examples/index.js +++ b/examples/index.js @@ -1,28 +1,16 @@ -import Vue from 'vue' -import Checkbox from './checkbox.vue' -import Button from './button.vue' -import Radio from './radio.vue' -import Grid from './grid.vue' -// import Dialog from './dialog.vue' -import Rate from './rate.vue' import './index.less' +import Vue from 'vue' +import VueMarkdown from 'vue-markdown' +import VueRouter from 'vue-router' +import routes from './routes' +Vue.use(VueRouter) + +const router = new VueRouter({ + mode: 'history', + routes, +}) +Vue.component('vue-markdown', VueMarkdown) new Vue({ el: '#app', - template: ` -
- - - - - -
- `, - components: { - AntButton: Button, - // AntDialog: Dialog, - Checkbox, - Grid, - Radio, - Rate, - }, + router, }) diff --git a/examples/routes.js b/examples/routes.js new file mode 100644 index 000000000..c9304af3b --- /dev/null +++ b/examples/routes.js @@ -0,0 +1,11 @@ +const AsyncComp = () => { + const pathnameArr = window.location.pathname.split('/') + const com = pathnameArr[1] || 'button' + const demo = pathnameArr[2] || 'basic' + return { + component: import(`../components/${com}/demo/${demo}.vue`), + } +} +export default [ + { path: '/*', component: AsyncComp }, +] diff --git a/package.json b/package.json index aa4cff6eb..af39ed717 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,11 @@ ], "devDependencies": { "babel-cli": "^6.26.0", + "babel-eslint": "^8.0.1", "babel-helper-vue-jsx-merge-props": "^2.0.2", "babel-loader": "^7.1.2", "babel-plugin-istanbul": "^4.1.1", + "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-plugin-syntax-jsx": "^6.18.0", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-vue-jsx": "^3.5.0", @@ -66,6 +68,7 @@ "stylelint-config-standard": "^17.0.0", "vue": "^2.4.4", "vue-loader": "^13.0.5", + "vue-router": "^3.0.1", "vue-template-compiler": "^2.4.4", "webpack": "^3.6.0", "webpack-dev-server": "^2.8.2" diff --git a/webpack.config.js b/webpack.config.js index d07132861..fbae8e042 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -48,6 +48,7 @@ module.exports = { extensions: ['.js', '.vue'], alias: { 'vue$': 'vue/dist/vue.esm.js', + 'antd': path.join(__dirname, 'components'), }, }, devServer: {