diff --git a/.babelrc b/.babelrc index c72eeb3a2..e3a543196 100644 --- a/.babelrc +++ b/.babelrc @@ -1,12 +1,9 @@ { - "presets": [ - [ - "es2015", - { "modules": false } - ] - ], - "plugins": [ - "transform-runtime", - "transform-vue-jsx" - ] -} \ No newline at end of file + "presets": [["env", { "modules": false, "loose": true }]], + "plugins": ["transform-vue-jsx", "transform-runtime", "transform-object-rest-spread"], + "env": { + "commonjs": { + "presets": [["env", { "modules": "commonjs", "loose": true }]] + } + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/README.md b/README.md index baf5f132e..2a90cd0c1 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,31 @@ npm i -S vant ``` ## Usage + +### Use [babel-plugin-import](https://github.com/ant-design/babel-plugin-import) (Recommended) + + ```js + // .babelrc or babel-loader option + { + "plugins": [ + ["import", { "libraryName": "vant", "style": true }] + ] + } + ``` + + Then you can import components from vant, equivalent to import manually below. + + ```js + // import js and css modularly, parsed by babel-plugin-import + import { Button } from 'vant'; + ``` + +### Manually import + + ```jsx + import { Button } from 'vant'; + import 'vant/lib/vant-css/button.css'; + ``` ### Import all components @@ -30,18 +55,6 @@ import 'vant/lib/vant-css/index.css'; Vue.use(vant); ``` -### On demand - -```javascript -import Vue from 'vue'; -import { Button, Cell } from 'vant'; -import 'vant/lib/vant-css/button.css'; -import 'vant/lib/vant-css/cell.css'; - -Vue.component(Button.name, Button); -Vue.component(Cell.name, Cell); -``` - ## Development ### Add a new component diff --git a/README.zh-CN.md b/README.zh-CN.md index b4596c24d..6cb129656 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -18,28 +18,40 @@ npm i -S vant ## 二、使用 -### 1. 导入所有组件 +### 使用 [babel-plugin-import](https://github.com/ant-design/babel-plugin-import) (推荐) + + ```js + // .babelrc or babel-loader option + { + "plugins": [ + ["import", { "libraryName": "vant", "style": true }] + ] + } + ``` + +   接着你可以直接引入 vant 组件,等价于下方的按需引入组件 + + ```js +   // 模块化地引入 js 和 css, 通过 babel-plugin-import 插件解析 +   import { Button } from 'vant'; + ``` + +### 按需引入组件 + + ```jsx + import { Button } from 'vant/lib/button'; + import 'vant/lib/vant-css/button.css'; + ``` + +### 导入所有组件 ```javascript import Vue from 'vue'; import vant from 'vant'; -// 你也可以使用自己的主题 import 'vant/lib/vant-css/index.css'; Vue.use(vant); ``` - -### 2. 按需导入组件 - -```javascript -import Vue from 'vue'; -import { Button, Cell } from 'vant'; -import 'vant/lib/vant-css/button.css'; -import 'vant/lib/vant-css/cell.css'; - -Vue.component(Button.name, Button); -Vue.component(Cell.name, Cell); -``` ## 三、开发 diff --git a/build/bin/build-all.js b/build/bin/build-all.js deleted file mode 100644 index 565edeee2..000000000 --- a/build/bin/build-all.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const components = require('../../components.json'); -const execSync = require('child_process').execSync; -const existsSync = require('fs').existsSync; -const path = require('path'); - -const componentPaths = []; - -delete components.font; - -Object.keys(components).forEach(key => { - const filePath = path.join(__dirname, `../../packages/${key}/webpack.conf.js`); - - if (existsSync(filePath)) { - componentPaths.push(`packages/${key}/webpack.conf.js`); - } -}); - -const paths = componentPaths.join(','); -const cli = `node_modules/.bin/webpack build -c ${paths} -p`; - -execSync(cli, { - stdio: 'inherit' -}); diff --git a/build/bin/build-components.js b/build/bin/build-components.js new file mode 100644 index 000000000..84a81f81c --- /dev/null +++ b/build/bin/build-components.js @@ -0,0 +1,52 @@ +/** + * 编译 components 到 lib 目录 + */ +const fs = require('fs-extra'); +const path = require('path'); +const compiler = require('vue-sfc-compiler'); +const libDir = path.resolve(__dirname, '../../lib'); +const srcDir = path.resolve(__dirname, '../../packages'); +require('shelljs/global'); + +// 清空 lib 目录 +fs.emptyDirSync(libDir); + +// 复制 packages +fs.copySync(srcDir, libDir); + +// 编译所有 .vue 文件到 .js +compileVueFiles(libDir); + +// babel 编译 +exec('cross-env BABEL_ENV=commonjs babel lib --out-dir lib'); + +function compileVueFiles(dir) { + const files = fs.readdirSync(dir); + + files.forEach(file => { + const absolutePath = path.resolve(dir, file); + + // 移除 vant-css + if (file.indexOf('vant-css') !== -1) { + fs.removeSync(absolutePath); + } + // 遍历文件夹 + else if (isDir(absolutePath)) { + return compileVueFiles(absolutePath); + } + // 编译 .vue 文件 + else if (/\.vue$/.test(file)) { + const source = fs.readFileSync(absolutePath, 'utf-8'); + fs.removeSync(absolutePath); + + const outputVuePath = absolutePath + '.js'; + const outputJsPath = absolutePath.replace('.vue', '.js'); + const output = fs.existsSync(outputJsPath) ? outputVuePath : outputJsPath; + fs.outputFileSync(output, compiler(source)); + } + }); +} + +function isDir(dir) { + return fs.lstatSync(dir).isDirectory(); +} diff --git a/build/bin/build-entry.js b/build/bin/build-entry.js index db939e763..27c7b9e96 100644 --- a/build/bin/build-entry.js +++ b/build/bin/build-entry.js @@ -1,11 +1,11 @@ -var Components = require('../../components.json'); +var Components = require('./get-components')(); var fs = require('fs'); var render = require('json-templater/string'); var uppercamelcase = require('uppercamelcase'); var path = require('path'); -var OUTPUT_PATH = path.join(__dirname, '../../src/index.js'); -var IMPORT_TEMPLATE = 'import {{name}} from \'../packages/{{package}}/index.js\';'; +var OUTPUT_PATH = path.join(__dirname, '../../packages/index.js'); +var IMPORT_TEMPLATE = 'import {{name}} from \'./{{package}}\';'; var ISNTALL_COMPONENT_TEMPLATE = ' {{name}}'; var MAIN_TEMPLATE = `{{include}} @@ -34,20 +34,17 @@ export { }; export default { install, - version, -{{list}} + version }; `; delete Components.font; -var ComponentNames = Object.keys(Components); - var includeComponentTemplate = []; var installTemplate = []; var listTemplate = []; -ComponentNames.forEach(name => { +Components.forEach(name => { var componentName = uppercamelcase(name); includeComponentTemplate.push(render(IMPORT_TEMPLATE, { diff --git a/build/bin/build-lib.js b/build/bin/build-lib.js index a9f47fad5..d20e2ba7c 100644 --- a/build/bin/build-lib.js +++ b/build/bin/build-lib.js @@ -3,56 +3,46 @@ * Steps: * 1. 清理目录 * 2. 构建 JS 入口文件 - * 3. 打包 JS 文件:vant.js && vant.min.js - * 4. 构建 CSS 文件:vant-css - * 5. 构建每个组件对应的 [component].js + * 3. 代码格式校验 + * 4. 构建每个组件对应的 [component].js + * 5. 构建 vant-css * 6. 生成每个组件目录下的 style 入口 - * 7. 编译 utils + * 7. 打包 JS 文件:vant.js && vant.min.js */ const fs = require('fs'); const path = require('path'); -const components = require('../../components.json'); +const components = require('./get-components')(); const chalk = require('chalk'); require('shelljs/global'); -// clean dir -log('Starting', 'clean'); -exec('npm run clean --silent'); -log('Finished', 'clean'); - -// build entry -log('Starting', 'build:entry'); -exec('npm run build:file --silent'); -log('Finished', 'build:entry'); - -// lint +// 1. lint log('Starting', 'lint'); exec('npm run lint --silent'); log('Finished', 'lint'); -// build vant.js -log('Starting', 'build:vant'); -exec('npm run build:vant --silent'); -log('Finished', 'build:vant'); +// 2. build entry +log('Starting', 'build:entry'); +exec('npm run build:file --silent'); +log('Finished', 'build:entry'); -// build [component].js +// 3. build [component].js log('Starting', 'build:component'); exec('npm run build:components --silent'); log('Finished', 'build:component'); -// build vant-css +// 4. build vant-css log('Starting', 'build:vant-css'); exec('npm run build:vant-css --silent'); log('Finished', 'build:vant-css'); -// build style entrys +// 5. build style entrys log('Starting', 'build:style-entries'); -Object.keys(components).forEach((componentName) => { +components.forEach((componentName) => { const dir = path.join(__dirname, '../../lib/', componentName, '/style'); const file = path.join(dir, 'index.js'); const cssPath = path.join(__dirname, '../../lib/vant-css/', `${componentName}.css`); - const content = [`require('../../vant-css/base.css');`]; + const content = []; if (fs.existsSync(cssPath)) { content.push(`require('../../vant-css/${componentName}.css');`); } @@ -61,10 +51,10 @@ Object.keys(components).forEach((componentName) => { }); log('Finished', 'build:style-entries'); -// build utils -log('Starting', 'build:utils'); -exec('npm run build:utils --silent'); -log('Finished', 'build:utils'); +// 6. build vant.js +log('Starting', 'build:vant'); +exec('npm run build:vant --silent'); +log('Finished', 'build:vant'); // helpers function log(status, action, breakLine) { diff --git a/build/bin/get-components.js b/build/bin/get-components.js new file mode 100644 index 000000000..9cc7a71fe --- /dev/null +++ b/build/bin/get-components.js @@ -0,0 +1,8 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = function() { + const dirs = fs.readdirSync(path.resolve(__dirname, '../../packages')); + const excludes = ['index.js', 'vant-css', 'mixins', 'utils']; + return dirs.filter(dirName => excludes.indexOf(dirName) === -1) +} diff --git a/build/bin/init.js b/build/bin/init.js index 2aa0b37d3..1cc94dc86 100644 --- a/build/bin/init.js +++ b/build/bin/init.js @@ -28,21 +28,4 @@ gulp.task('copy', function(callback) { }); }); - -// 添加到 components.json -gulp.task('addComponents', function(callback) { - const componentsFile = require('../../components.json'); - if (componentsFile[name]) { - console.error(`${name} 已存在.`); - process.exit(1); - } - componentsFile[name] = `./packages/${name}/index.js`; - fileSave(path.join(__dirname, '../../components.json')) - .write(JSON.stringify(componentsFile, null, ' '), 'utf8') - .end('\n'); - gutil.log('-------> components.json文件更新成功'); - gutil.log(gutil.colors.yellow('-------> 请无视下面的make报错')); -}); - -runSequence('copy', 'addComponents'); - +runSequence('copy'); diff --git a/build/genExamples.js b/build/genExamples.js deleted file mode 100644 index c668082f9..000000000 --- a/build/genExamples.js +++ /dev/null @@ -1,16 +0,0 @@ -const path = require('path'); -const docConfig = require('../docs/src/doc.config'); -const { extractExample } = require('zan-doc/src/helper'); - -function extract(watch = false) { - extractExample({ - src: path.resolve(__dirname, '../docs/examples-docs'), - dist: path.resolve(__dirname, '../docs/examples-dist'), - nav: docConfig['zh-CN'].nav, - watch - }); -} - -module.exports = function watch(isProduction) { - extract(!isProduction); -}; diff --git a/build/webpack.build.js b/build/webpack.build.js index 0ce2bb610..2b53cbae7 100644 --- a/build/webpack.build.js +++ b/build/webpack.build.js @@ -3,7 +3,7 @@ const config = require('./webpack.config.dev.js'); const isMinify = process.argv.indexOf('-p') !== -1; config.entry = { - 'vant': './src/index.js' + 'vant': './packages/index.js' }; config.output = { diff --git a/build/webpack.components.js b/build/webpack.components.js deleted file mode 100644 index d5a3c18fb..000000000 --- a/build/webpack.components.js +++ /dev/null @@ -1,31 +0,0 @@ -const path = require('path'); -const Components = require('../components.json'); -const config = require('./webpack.build.js'); -const webpack = require('webpack'); - -delete config.devtool; - -const entry = {}; -Object.keys(Components).forEach(key => { - entry[key + '/index'] = Components[key]; -}); - -config.entry = entry; - -config.externals = { - vue: { - root: 'Vue', - commonjs: 'vue', - commonjs2: 'vue', - amd: 'vue' - } -}; - -config.output = { - path: path.join(__dirname, '../lib'), - filename: '[name].js', - libraryExport: "default", - libraryTarget: 'umd' -}; - -module.exports = config; diff --git a/build/webpack.config.dev.js b/build/webpack.config.dev.js index 9cad7ac96..e38ba86e3 100644 --- a/build/webpack.config.dev.js +++ b/build/webpack.config.dev.js @@ -6,15 +6,23 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin'); const isProduction = process.env.NODE_ENV === 'production'; +const docConfig = require('../docs/src/doc.config'); +const { extractExample } = require('zan-doc/src/helper'); const styleLoaders = [ { loader: 'css-loader' }, { loader: 'postcss-loader', options: { sourceMap: true } } ]; -require('./genExamples')(isProduction); + +// extract [components].vue from [components].md +extractExample({ + src: path.resolve(__dirname, '../docs/examples-docs'), + dist: path.resolve(__dirname, '../docs/examples-dist'), + nav: docConfig['zh-CN'].nav, + watch: !isProduction +}); module.exports = { entry: { - vendor: ['vue', 'vue-router', 'zan-doc'], 'vant-docs': './docs/src/index.js', 'vant-examples': './docs/src/examples.js' }, @@ -22,9 +30,11 @@ module.exports = { path: path.join(__dirname, '../docs/dist'), publicPath: '/', filename: '[name].js', - umdNamedDefine: true + umdNamedDefine: true, + chunkFilename: 'async.[name].js' }, devServer: { + host: '0.0.0.0', historyApiFallback: { rewrites: [ { from: /^\/zanui\/vue\/examples/, to: '/examples.html' }, @@ -37,8 +47,7 @@ module.exports = { modules: [path.join(__dirname, '../node_modules'), 'node_modules'], extensions: ['.js', '.vue', '.css'], alias: { - vue$: 'vue/dist/vue.esm.js', - src: path.join(__dirname, '../src'), + vue: 'vue/dist/vue.runtime.esm.js', packages: path.join(__dirname, '../packages'), lib: path.join(__dirname, '../lib'), components: path.join(__dirname, '../docs/src/components') @@ -52,6 +61,7 @@ module.exports = { { loader: 'vue-loader', options: { + preserveWhitespace: false, loaders: { postcss: ExtractTextPlugin.extract({ use: styleLoaders, @@ -68,7 +78,7 @@ module.exports = { }, { test: /\.js$/, - exclude: /node_modules|vue-router\/|vue-loader\/|vue-hot-reload-api\//, + exclude: /node_modules|vue-router\/|vue-loader\//, loader: 'babel-loader' }, { @@ -105,7 +115,7 @@ module.exports = { }, render: function(tokens, idx) { - return tokens[idx].nesting === 1 + return tokens[idx].nesting === 1 ? `
` :`
\n`; } @@ -131,6 +141,10 @@ module.exports = { filename: 'examples.html', inject: true }), + new webpack.optimize.CommonsChunkPlugin({ + name: 'vendor', + minChunks: 2 + }), new webpack.HotModuleReplacementPlugin(), new OptimizeCssAssetsPlugin(), new ExtractTextPlugin({ diff --git a/build/webpack.config.prod.js b/build/webpack.config.prod.js index d4a45855b..204bf81a5 100644 --- a/build/webpack.config.prod.js +++ b/build/webpack.config.prod.js @@ -6,9 +6,10 @@ var devConfig = require('./webpack.config.dev.js'); module.exports = merge(devConfig, { output: { path: path.join(__dirname, '../docs/dist'), - publicPath: 'https://b.yzcdn.cn/zanui/vue', + publicPath: 'https://b.yzcdn.cn/zanui/vue/', filename: '[name].[hash:8].js', - umdNamedDefine: true + umdNamedDefine: true, + chunkFilename: 'async.[name].[chunkhash:8].js' }, devtool: false, plugins: [ diff --git a/components.json b/components.json deleted file mode 100644 index dd4b25daa..000000000 --- a/components.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "button": "./packages/button/index.js", - "switch": "./packages/switch/index.js", - "field": "./packages/field/index.js", - "radio": "./packages/radio/index.js", - "cell": "./packages/cell/index.js", - "icon": "./packages/icon/index.js", - "cell-group": "./packages/cell-group/index.js", - "cell-swipe": "./packages/cell-swipe/index.js", - "popup": "./packages/popup/index.js", - "dialog": "./packages/dialog/index.js", - "picker": "./packages/picker/index.js", - "radio-group": "./packages/radio-group/index.js", - "waterfall": "./packages/waterfall/index.js", - "loading": "./packages/loading/index.js", - "panel": "./packages/panel/index.js", - "card": "./packages/card/index.js", - "steps": "./packages/steps/index.js", - "tag": "./packages/tag/index.js", - "checkbox": "./packages/checkbox/index.js", - "checkbox-group": "./packages/checkbox-group/index.js", - "badge-group": "./packages/badge-group/index.js", - "badge": "./packages/badge/index.js", - "search": "./packages/search/index.js", - "step": "./packages/step/index.js", - "tabs": "./packages/tabs/index.js", - "tab": "./packages/tab/index.js", - "lazyload": "./packages/lazyload/index.js", - "image-preview": "./packages/image-preview/index.js", - "col": "./packages/col/index.js", - "row": "./packages/row/index.js", - "actionsheet": "./packages/actionsheet/index.js", - "quantity": "./packages/quantity/index.js", - "progress": "./packages/progress/index.js", - "toast": "./packages/toast/index.js", - "uploader": "./packages/uploader/index.js", - "swipe": "./packages/swipe/index.js", - "swipe-item": "./packages/swipe-item/index.js", - "datetime-picker": "./packages/datetime-picker/index.js" -} diff --git a/docs/assets/docs.css b/docs/assets/docs.css deleted file mode 100644 index bbcf5edb1..000000000 --- a/docs/assets/docs.css +++ /dev/null @@ -1,206 +0,0 @@ -html, body, div, span, applet, object, iframe, -h1, h2, h3, h4, h5, h6, p, blockquote, pre, -a, abbr, acronym, address, big, cite, code, -del, dfn, em, img, ins, kbd, q, s, samp, -small, strike, strong, sub, sup, tt, var, -b, u, i, center, -dl, dt, dd, ol, ul, li, -fieldset, form, label, legend, -table, caption, tbody, tfoot, thead, tr, th, td, -article, aside, canvas, details, embed, -figure, figcaption, footer, header, hgroup, -menu, nav, output, ruby, section, summary, -time, mark, audio, video { - margin: 0; - padding: 0; - border: 0; - font-size: 100%; - vertical-align: baseline; -} - -body { - font-family: 'Helvetica Neue',Helvetica,'PingFang SC','Hiragino Sans GB','Microsoft YaHei',SimSun,sans-serif; - font-weight: 400; - -webkit-font-smoothing: antialiased; - background-color: #f8f8f8; -} - -a { - color: #4078c0; - text-decoration: none; -} - -button, input, select, textarea { - font-family: inherit; - font-size: inherit; - line-height: inherit; - color: inherit; -} - -ul, ol { - list-style: none; -} - -code.hljs { - line-height: 1.5; - font-family: Menlo, Monaco, Consolas, Courier, monospace; - font-size: 12px; - padding: 20px; - background-color: #f8f8f8; - border: solid 1px #E5E5E5; - margin-bottom: 25px; - border-radius: 4px; - -webkit-font-smoothing: auto; -} - -.clearfix { - &::before { - display: table; - content: ""; - } - - &::after { - display: table; - content: ""; - clear: both; - } -} - -.main-content { - margin: 130px 20px 40px; - padding-top: 20px; -} - -.page-container { - background-color: #fff; - position: relative; - display: flex; - width: 100%; - overflow: hidden; -} - -.page-content { - box-sizing: border-box; - flex: 1; - - section { - padding: 0 40px; - - > h1, - > h2, - > h3, - > h4, - > h5, - > h6 { - color: #333; - line-height: 1.5; - margin: 20px 0; - font-weight: normal; - - .header-anchor { - float: left; - margin-left: -20px; - opacity: 0; - cursor: pointer; - - &:hover { - opacity: .4; - } - } - } - - > h1 { - font-size: 40px; - } - - > h2 { - font-size: 36px; - } - - > h3 { - font-size: 30px; - } - - > h4 { - font-size: 24px; - } - - > h5 { - font-size: 14px - } - - > h6 { - font-size: 14px; - color: #666; - } - - > p { - font-size: 14px; - line-height: 20px; - color: #666; - margin: 14px 0; - } - - > ul li, - > ol li { - color: #666; - font-size: 14px; - line-height: 20px; - margin: 10px 0 10px 20px; - padding-left: 20px; - position: relative; - - &::before { - content: ''; - position: absolute; - width: 8px; - height: 8px; - box-sizing: border-box; - border: 2px solid #999; - border-radius: 50%; - top: 6px; - left: 0; - } - - li { - margin-left: 0; - } - } - } - - p > code, - .table code, - li > code { - background-color: #F2F2F2; - display: inline-block; - border: 1px solid #E5E5E5; - padding: 2px 4px; - color: #333; - margin: 0 3px; - } -} - -.table { - border-collapse: collapse; - width: 100%; - background-color: #fff; - color: #333; - font-size: 14px; - margin-bottom: 45px; - - th { - text-align: left; - border: 1px solid #E5E5E5; - background-color: #F2F2F2; - padding: 10px; - - &:first-child { - padding-left: 10px; - } - } - - td { - border: 1px solid #E5E5E5; - padding: 10px; - } -} diff --git a/docs/examples-docs/actionsheet.md b/docs/examples-docs/actionsheet.md index 92a645069..09cd0fef6 100644 --- a/docs/examples-docs/actionsheet.md +++ b/docs/examples-docs/actionsheet.md @@ -15,11 +15,7 @@ -## ActionSheet 行动按钮 +## Actionsheet 行动按钮 ### 使用指南 +``` javascript +import { Actionsheet } from 'vant'; -如果你已经按照快速上手中引入了整个`vant`,以下**组件注册**就可以忽略了,因为你已经全局注册了`vant`中的全部组件。 - -#### 全局注册 - -你可以在全局注册`ActionSheet`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`ActionSheet`组件了: - -```js -import Vue from 'vue'; -import { ActionSheet } from 'vant'; -import 'vant/lib/vant-css/actionSheet.css'; - -Vue.component(ActionSheet.name, ActionSheet); -``` - -#### 局部注册 - -如果你只是想在某个组件中使用,你可以在对应组件中注册`ActionSheet`组件,这样只能在你注册的组件中使用`ActionSheet`: - -```js -import { ActionSheet } from 'vant'; -import 'vant/lib/vant-css/actionSheet.css'; - -export default { - components: { - 'van-actionSheet': ActionSheet - } -}; +Vue.component(Actionsheet.name, Actionsheet); ``` ### 代码演示 @@ -141,11 +113,11 @@ export default { ``` ::: -#### 带取消按钮的ActionSheet +#### 带取消按钮的 Actionsheet -如果传入了`cancelText`属性,且不为空,则会在下方显示一个取消按钮,点击会将当前`ActionSheet`关闭。 +如果传入了`cancelText`属性,且不为空,则会在下方显示一个取消按钮,点击会将当前`Actionsheet`关闭。 -:::demo 带取消按钮的ActionSheet +:::demo 带取消按钮的 Actionsheet ```html 弹出带取消按钮的actionsheet @@ -184,11 +156,11 @@ export default { ``` ::: -#### 带标题的ActionSheet +#### 带标题的 Actionsheet -如果传入了`title`属性,且不为空,则另外一种样式的`ActionSheet`,里面内容需要自定义。 +如果传入了`title`属性,且不为空,则另外一种样式的`Actionsheet`,里面内容需要自定义。 -:::demo 带标题的ActionSheet +:::demo 带标题的 Actionsheet ```html 弹出带标题的actionsheet @@ -197,11 +169,6 @@ export default { ``` ::: -点击以下按钮查看手机端效果: - -点击查看手机端效果 - - ### API | 参数 | 说明 | 类型 | 默认值 | 可选值 | @@ -210,10 +177,11 @@ export default { | title | 标题 | `String` | | | | cancelText | 取消按钮文案 | `String` | | | | overlay | 是否显示遮罩 | `Boolean` | | | -| closeOnClickOverlay | 点击遮罩是否关闭`ActionSheet` | `Boolean` | | | +| closeOnClickOverlay | 点击遮罩是否关闭`Actionsheet` | `Boolean` | | | ### actions + `API`中的`actions`为一个对象数组,数组中的每一个对象配置每一列,每一列有以下`key`: | key | 说明 | diff --git a/docs/examples-docs/badge.md b/docs/examples-docs/badge.md index c325671a3..6da67fc0c 100644 --- a/docs/examples-docs/badge.md +++ b/docs/examples-docs/badge.md @@ -1,112 +1,89 @@ ## Badge 徽章 ### 使用指南 - -如果你已经按照快速上手中引入了整个`vant`,以下**组件注册**就可以忽略了,因为你已经全局注册了`vant`中的全部组件。 - -#### 全局注册 - -你可以在全局注册`Badge`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`Badge`组件了: - -```js -import Vue from 'vue'; -import { Badge, BadgeGroup } from 'vant'; -import 'vant/lib/vant-css/badge.css'; +``` javascript +import { Badge } from 'vant'; Vue.component(Badge.name, Badge); -Vue.component(BadgeGroup.name, BadgeGroup); -``` - -#### 局部注册 - -如果你只是想在某个组件中使用,你可以在对应组件中注册`Badge`组件,这样只能在你注册的组件中使用`Badge`: - -```js -import { Badge, BadgeGroup } from 'vant'; -import 'vant/lib/vant-css/badge.css'; - -export default { - components: { - 'van-badge': Badge, - 'van-badge-group': BadgeGroup - } -}; ``` ### 代码演示 #### 基础用法 -默认情况下激活第一个`badge`。 +通过在`van-badge-group`上设置`active-key`属性来控制选中的`badge` :::demo 基础用法 ```html -
- - - - - - -
+ + + + + + +``` + +``` javascript +export default { + data() { + return { + activeKey: 0 + }; + }, + methods: { + onClick(key) { + this.activeKey = key; + } + } +}; ``` ::: -#### 选中某个badge -如果想默认选中某个`badge`,你可以在`van-badge-group`上设置`activeKey`属性,属性值为对应的`badge`索引。 +### BadgeGroup API -:::demo 选中某个badge -```html -
- - - - - - -
-``` -::: - -### z-badge-group API - -| 参数 | 说明 | 类型 | 默认值 | 必须 | +| 参数 | 说明 | 类型 | 默认值 | 可选值 | |-----------|-----------|-----------|-------------|-------------| -| active-key | 激活的`badge`的索引 | `string` | `0`但必须子badge里的mark是有`0`位索引 | | +| active-key | 选中`badge`的索引 | `String | Number` | `0` | - | - -### z-badge API -| 参数 | 说明 | 类型 | 默认值 | 必须 | +### Badge API +| 参数 | 说明 | 类型 | 默认值 | 可选值 | |-----------|-----------|-----------|-------------|-------------| -| title | badge的文案标题 | `string` | `''` | `required` | -| info | 当前badge的提示消息 | `string` | `''` | | -| url | 跳转链接 | `string` | 链接直接跳转或者hash | | +| title | 内容 | `String` | `''` | - | +| info | 提示消息 | `String` | `''` | - | +| url | 跳转链接 | `String` | - | - | diff --git a/docs/examples-docs/button.md b/docs/examples-docs/button.md index 86399691d..a5bfd47d2 100644 --- a/docs/examples-docs/button.md +++ b/docs/examples-docs/button.md @@ -1,19 +1,25 @@ @@ -21,137 +27,75 @@ ## Button 按钮 ### 使用指南 - -如果你已经按照快速上手中引入了整个`vant`,以下**组件注册**就可以忽略了,因为你已经全局注册了`vant`中的全部组件。 - -#### 全局注册 - -你可以在全局注册`Button`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`Button`组件了: - -```js -import Vue from 'vue'; +``` javascript import { Button } from 'vant'; -import 'vant/lib/vant-css/button.css'; Vue.component(Button.name, Button); ``` -#### 局部注册 - -如果你只是想在某个组件中使用,你可以在对应组件中注册`Button`组件,这样只能在你注册的组件中使用`Button`: - -```js -import { Button } from 'vant'; -import 'vant/lib/vant-css/button.css'; - -export default { - components: { - 'van-button': Button - } -}; -``` - ### 代码演示 -#### 按钮功能 +#### 按钮类型 -只接受`primary`, `default`, `danger`三种类型,默认`default`。 +支持`default`、`primary`、`danger`三种类型,默认为`default` -:::demo 按钮功能 +:::demo 按钮类型 ```html - - - default - - - primary - - - danger - - -``` -::: - -#### 禁用状态 - -在组件上加上`disabled`属性即可,此时按钮不可点击。 - -:::demo 禁用状态 -```html - - - diabled - - +Default +Primary +Danger ``` ::: #### 按钮尺寸 -只接受`large`, `normal`, `small`, `mini`四种尺寸,默认`normal`。`large`按钮默认100%宽度。 +支持`large`、`normal`、`small`、`mini`四种尺寸,默认为`normal` :::demo 按钮尺寸 ```html - - - large - - - normal - - - small - - - mini - - +Large +Normal +Small +Mini +``` +::: + +#### 禁用状态 + +通过`disabled`属性来禁用按钮,此时按钮不可点击 + +:::demo 禁用状态 +```html +Diabled +``` +::: + +#### 加载状态 + +:::demo 加载状态 +```html + ``` ::: #### 自定义按钮标签 -按钮默认是`button`标签,可以使用`tag`属性修改为一个`a`标签。 +按钮标签默认为`button`,可以使用`tag`属性来修改按钮标签 :::demo 自定义按钮标签 ```html - - - a标签按钮 - - -``` -::: - -#### loading按钮 - -`loading`状态的按钮。 - -:::demo loading按钮 -```html - - - loading - - - - - + + a 标签按钮 + ``` ::: #### 页面底部操作按钮 -一般用于`fixed`在底部的区域或是`popup`弹层的底部,一般只使用`primary`和`normal`两种状态。 - :::demo 页面底部操作按钮 ```html - - - 立即购买 - - +立即购买 + 加入购物车 @@ -167,10 +111,11 @@ export default { | 参数 | 说明 | 类型 | 默认值 | 可选值 | |-----------|-----------|-----------|-------------|-------------| -| type | 按钮类型 | `string` | `default` | `primary`, `danger` | -| size | 按钮尺寸 | `string` | `normal` | `large`, `small`, `mini` | -| tag | 按钮标签 | `string` | `button` | 任何有意义的`html`标签, 如`a`, `span`等 | -| diabled | 按钮是否禁用 | `boolean` | `false` | | -| block | 按钮是否显示为块级元素 | `boolean` | `false` | | -| bottomAction | 按钮是否显示为底部行动按钮,一般显示在页面底部,有特殊样式 | `boolean` | `false` | | - +| type | 按钮类型 | `String` | `default` | `primary` `danger` | +| size | 按钮尺寸 | `String` | `normal` | `large` `small` `mini` | +| tag | 按钮标签 | `String` | `button` | 任意`HTML`标签 | +| nativeType | 按钮类型(原生) | `String` | `''` | - | +| diabled | 是否禁用 | `Boolean` | `false` | - | +| loading | 是否显示为加载状态 | `Boolean` | `false` | - | +| block | 是否为块级元素 | `Boolean` | `false` | - | +| bottomAction | 是否为底部行动按钮 | `Boolean` | `false` | - | diff --git a/docs/examples-docs/card.md b/docs/examples-docs/card.md index 74d652d65..2c586a78a 100644 --- a/docs/examples-docs/card.md +++ b/docs/examples-docs/card.md @@ -1,49 +1,29 @@ + + ## Card 图文组件 ### 使用指南 - -如果你已经按照快速上手中引入了整个`vant`,以下**组件注册**就可以忽略了,因为你已经全局注册了`vant`中的全部组件。 - -#### 全局注册 - -你可以在全局注册`Card`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`Card`组件了: - -```js -import Vue from 'vue'; +``` javascript import { Card } from 'vant'; -import 'vant/lib/vant-css/card.css'; Vue.component(Card.name, Card); ``` -#### 局部注册 - -如果你只是想在某个组件中使用,你可以在对应组件中注册`Card`组件,这样只能在你注册的组件中使用`Card`: - -```js -import { Card } from 'vant'; -import 'vant/lib/vant-css/card.css'; - -export default { - components: { - 'van-card': Card - } -}; -``` - ### 代码演示 #### 基础用法 -当没有底部按钮时,右侧内容会居中显示。 - :::demo 基础用法 ```html - - + ``` ::: @@ -53,10 +33,9 @@ export default { :::demo 高级用法 ```html - +
-

商品名称是什么,两行显示状态如效果图,多余多余多余两行显示状态如效果图,多余多余多余两行显示状态如效果图,多余多余多余两行显示状态如效果图,多余多余多余两行显示状态如效果图,多余多余多余

+

商品名称

¥ 2.00
@@ -74,11 +53,10 @@ export default { | 参数 | 说明 | 类型 | 默认值 | 可选值 | |-----------|-----------|-----------|-------------|-------------| -| thumb | 左侧图片 | `string` | | | -| title | 标题 | `string` | | | -| desc | 描述 | `string` | | | -| centered | 内容是否垂直居中 | `string` | `false` | | - +| thumb | 左侧图片 | `String` | - | - | +| title | 标题 | `String` | - | - | +| desc | 描述 | `String` | - | - | +| centered | 内容是否垂直居中 | `String` | `false` | - | ### Slot @@ -86,6 +64,6 @@ export default { |-----------|-----------| | title | 自定义标题 | | desc | 自定义描述 | -| tags | 自定义tags | -| thumb | 自定义thumb | -| footer | 自定义footer | +| tags | 自定义 tags | +| thumb | 自定义 thumb | +| footer | 自定义 footer | diff --git a/docs/examples-docs/cell-swipe.md b/docs/examples-docs/cell-swipe.md index beafe0aa2..a16494da7 100644 --- a/docs/examples-docs/cell-swipe.md +++ b/docs/examples-docs/cell-swipe.md @@ -1,6 +1,6 @@ ## CellSwipe 滑动单元格 ### 使用指南 - -如果你已经按照快速上手中引入了整个`vant`,以下**组件注册**就可以忽略了,因为你已经全局注册了`vant`中的全部组件。 - -#### 全局注册 - -你可以在全局注册`Cell Swipe`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`Cell Swipe`组件了: - -```js -import Vue from 'vue'; +``` javascript import { CellSwipe } from 'vant'; -import 'vant/lib/vant-css/cell-swipe.css'; Vue.component(CellSwipe.name, CellSwipe); ``` -#### 局部注册 - -如果你只是想在某个组件中使用,你可以在对应组件中注册`Cell Swipe`组件,这样只能在你注册的组件中使用`Cell Swipe`: - -```js -import { CellSwipe } from 'vant'; - -export default { - components: { - 'van-cell-swipe': CellSwipe - } -}; -``` - ### 代码演示 #### 基础用法 @@ -59,32 +32,26 @@ export default { :::demo 基础用法 ```html + 选择 - - - 删除 - - - 选择 - + 删除 ``` ::: - ### API | 参数 | 说明 | 类型 | 默认值 | 可选值 | |-----------|-----------|-----------|-------------|-------------| -| right-width | 右侧滑动按钮宽度 | `number` | 0 | | -| left-width | 左侧滑动按钮宽度 | `number` | 0 | | +| left-width | 左侧滑动区域宽度 | `Number` | `0` | - | +| right-width | 右侧滑动区域宽度 | `Number` | `0` | - | ### Slot | name | 描述 | |-----------|-----------| | - | 自定义显示内容 | -| right | 右侧滑动内容 | | left | 左侧滑动内容 | +| right | 右侧滑动内容 | diff --git a/docs/examples-docs/cell.md b/docs/examples-docs/cell.md index b9d9beed0..bbad3c505 100644 --- a/docs/examples-docs/cell.md +++ b/docs/examples-docs/cell.md @@ -8,125 +8,95 @@ export default { }; + + ## Cell 单元格 ### 使用指南 - -如果你已经按照快速上手中引入了整个`vant`,以下**组件注册**就可以忽略了,因为你已经全局注册了`vant`中的全部组件。 - -#### 全局注册 - -你可以在全局注册`Cell`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`Cell`组件了: - -```js -import Vue from 'vue'; +``` javascript import { Cell, CellGroup } from 'vant'; -import 'vant/lib/vant-css/cell.css'; -Vue.component(CellGroup.name, CellGroup); Vue.component(Cell.name, Cell); -``` - -#### 局部注册 - -如果你只是想在某个组件中使用,你可以在对应组件中注册`Cell`组件,这样只能在你注册的组件中使用`Cell`: - -```js -import { Cell } from 'vant'; -import 'vant/lib/vant-css/cell.css'; - -export default { - components: { - 'van-cell-group': CellGroup, - 'van-cell': Cell - } -}; +Vue.component(CellGroup.name, CellGroup); ``` ### 代码演示 #### 基础用法 -你可以将`van-cell-group`组件看成一个容器即可。 +将`van-cell-group`组件看成一个容器即可 :::demo 基础用法 ```html - + ``` ::: #### 只设置value - -只设置`value`时会向左对齐。 +只设置`value`时会向左对齐 :::demo 只设置value ```html - - + ``` ::: -#### 标题带描述信息 - -传入`label`属性,属性值为描述信息的值。 - -:::demo 标题带描述信息 +#### 展示图标 +通过`icon`属性在标题左侧展示图标 +:::demo 展示图标 ```html - - + ``` ::: -#### 带图标 +#### 展示箭头 +传入`isLink`属性则会在右侧显示箭头 -传入`icon`属性。 - -:::demo 带图标 +:::demo 展示箭头 ```html - - - -``` -::: - -#### 可点击的链接 - -传入`url`属性,传入`isLink`属性则会在右侧显示箭头。 - -:::demo 可点击的链接 -```html - - - + + ``` ::: #### 高级用法 - -如以上用法不能满足你的需求,可以使用对应的`slot`来自定义显示的内容。包含三个`slot`,默认`slot`、`icon`、`title`和`right-icon`的`slot`。 +如以上用法不能满足你的需求,可以使用对应的`slot`来自定义显示的内容 :::demo 高级用法 ```html - + - + @@ -137,12 +107,13 @@ export default { | 参数 | 说明 | 类型 | 默认值 | 可选值 | |-----------|-----------|-----------|-------------|-------------| -| icon | 左侧图标 | `string` | | | -| title | 左侧标题 | `string` | | | -| value | 右侧内容 | `string` | | | -| isLink | 是否为链接,链接会在右侧出现箭头 | `boolean` | | | -| url | 跳转链接 | `string` | | | -| label | 描述信息,显示在标题下方 | `string` | | | +| icon | 左侧图标 | `String` | - | - | +| title | 左侧标题 | `String` | - | - | +| value | 右侧内容 | `String` | - | - | +| label | 标题下方的描述信息 | `String` | - | - | +| url | 跳转链接 | `String` | - | - | +| isLink | 是否展示右侧箭头 | `Boolean` | `false` | - | +| required | 是否显示表单必填符号 | `Boolean` | `false` | - | ### Slot diff --git a/docs/examples-docs/changelog.md b/docs/examples-docs/changelog.md index ac512409c..de6ed92ed 100644 --- a/docs/examples-docs/changelog.md +++ b/docs/examples-docs/changelog.md @@ -1,5 +1,101 @@ ## 更新日志 +## [v0.8.6](https://github.com/youzan/vant/tree/v0.8.6) (2017-08-24) +[Full Changelog](https://github.com/youzan/vant/compare/v0.8.5...v0.8.6) + +**非兼容更新和新特性:** + +- dalete merge && class operating methods [\#88](https://github.com/youzan/vant/pull/88) ([chenjiahan](https://github.com/chenjiahan)) +- directory adjust: delete entry index.js [\#87](https://github.com/youzan/vant/pull/87) ([chenjiahan](https://github.com/chenjiahan)) +- Button: reduce unnecessary styles [\#86](https://github.com/youzan/vant/pull/86) ([chenjiahan](https://github.com/chenjiahan)) +- Layout: optimize doc [\#85](https://github.com/youzan/vant/pull/85) ([chenjiahan](https://github.com/chenjiahan)) + +**修复:** + +- Fix datetime-picker init value [\#89](https://github.com/youzan/vant/pull/89) ([w91](https://github.com/w91)) + +**处理的 Issue:** + +- When 'showIndicators' set to 'false' The second image does not show [\#80](https://github.com/youzan/vant/issues/80) + +## [v0.8.5](https://github.com/youzan/vant/tree/v0.8.5) (2017-08-21) +[Full Changelog](https://github.com/youzan/vant/compare/v0.8.4...v0.8.5) + +**非兼容更新和新特性:** + +- Doc: add usage guide && top progress [\#83](https://github.com/youzan/vant/pull/83) ([chenjiahan](https://github.com/chenjiahan)) + +**修复:** + +- Popup: not preventScroll by default [\#84](https://github.com/youzan/vant/pull/84) ([chenjiahan](https://github.com/chenjiahan)) +- fix: swipe sometimes will change to drag image [\#81](https://github.com/youzan/vant/pull/81) ([pangxie1991](https://github.com/pangxie1991)) + +**处理的 Issue:** + +- Href link does not work [\#82](https://github.com/youzan/vant/issues/82) +- Swipe image not displayed [\#79](https://github.com/youzan/vant/issues/79) + +## [v0.8.4](https://github.com/youzan/vant/tree/v0.8.4) (2017-08-18) +[Full Changelog](https://github.com/youzan/vant/compare/v0.8.3...v0.8.4) + +**修复:** + +- fix: field 计算autosize,需要nextTick [\#78](https://github.com/youzan/vant/pull/78) ([pangxie1991](https://github.com/pangxie1991)) + +## [v0.8.3](https://github.com/youzan/vant/tree/v0.8.3) (2017-08-18) +[Full Changelog](https://github.com/youzan/vant/compare/v0.8.1...v0.8.3) + +**修复:** + +- fix: dialog wrong z-index [\#77](https://github.com/youzan/vant/pull/77) ([chenjiahan](https://github.com/chenjiahan)) + +## [v0.8.1](https://github.com/youzan/vant/tree/v0.8.1) (2017-08-18) +[Full Changelog](https://github.com/youzan/vant/compare/v0.8.0...v0.8.1) + +**非兼容更新和新特性:** + +- field 增加icon slot支持 [\#76](https://github.com/youzan/vant/pull/76) ([pangxie1991](https://github.com/pangxie1991)) + +## [v0.8.0](https://github.com/youzan/vant/tree/v0.8.0) (2017-08-17) +[Full Changelog](https://github.com/youzan/vant/compare/v0.7.10...v0.8.0) + +**非兼容更新和新特性:** + +- Optimize component building, reduce dist file size [\#74](https://github.com/youzan/vant/pull/74) ([chenjiahan](https://github.com/chenjiahan)) + +## [v0.7.10](https://github.com/youzan/vant/tree/v0.7.10) (2017-08-16) +[Full Changelog](https://github.com/youzan/vant/compare/v0.7.8...v0.7.10) + +**修复:** + +- fix: 修复popup和dialog同时出现时,几率出现dialog被挡住的情况 [\#75](https://github.com/youzan/vant/pull/75) ([pangxie1991](https://github.com/pangxie1991)) +- 修复:popup滚动穿透 [\#73](https://github.com/youzan/vant/pull/73) ([cookfront](https://github.com/cookfront)) + +## [v0.7.8](https://github.com/youzan/vant/tree/v0.7.8) (2017-08-10) +[Full Changelog](https://github.com/youzan/vant/compare/v0.7.7...v0.7.8) + +**非兼容更新和新特性:** + +- 补充 babel-plugin-import 文档 [\#71](https://github.com/youzan/vant/pull/71) ([chenjiahan](https://github.com/chenjiahan)) + +**修复:** + +- not require reset.css by default [\#72](https://github.com/youzan/vant/pull/72) ([chenjiahan](https://github.com/chenjiahan)) + +## [v0.7.7](https://github.com/youzan/vant/tree/v0.7.7) (2017-08-09) +[Full Changelog](https://github.com/youzan/vant/compare/v0.7.6...v0.7.7) + +**修复:** + +- Fixed: one page Swipe components error [\#70](https://github.com/youzan/vant/pull/70) ([Raistlin916](https://github.com/Raistlin916)) + +## [v0.7.6](https://github.com/youzan/vant/tree/v0.7.6) (2017-08-08) +[Full Changelog](https://github.com/youzan/vant/compare/v0.7.5...v0.7.6) + +**非兼容更新和新特性:** + +- 新增几个icon [\#69](https://github.com/youzan/vant/pull/69) ([cookfront](https://github.com/cookfront)) + ## [v0.7.5](https://github.com/youzan/vant/tree/v0.7.5) (2017-08-08) [Full Changelog](https://github.com/youzan/vant/compare/v0.7.3...v0.7.5) diff --git a/docs/examples-docs/checkbox.md b/docs/examples-docs/checkbox.md index a45ecf16d..fdfcba1d7 100644 --- a/docs/examples-docs/checkbox.md +++ b/docs/examples-docs/checkbox.md @@ -36,36 +36,10 @@ export default { ## Checkbox 复选框 ### 使用指南 - -如果你已经按照快速上手中引入了整个`vant`,以下**组件注册**就可以忽略了,因为你已经全局注册了`vant`中的全部组件。 - -#### 全局注册 - -你可以在全局注册`Checkbox`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`Checkbox`组件了: - -```js -import Vue from 'vue'; -import { Checkbox, CheckboxGroup } from 'vant'; -import 'vant/lib/vant-css/checkbox.css'; +``` javascript +import { Checkbox } from 'vant'; Vue.component(Checkbox.name, Checkbox); -Vue.component(CheckboxGroup.name, CheckboxGroup); -``` - -#### 局部注册 - -如果你只是想在某个组件中使用,你可以在对应组件中注册`Checkbox`组件,这样只能在你注册的组件中使用`Checkbox`: - -```js -import { Checkbox, CheckboxGroup } from 'vant'; -import 'vant/lib/vant-css/checkbox.css'; - -export default { - components: { - 'van-checkbox': Checkbox, - 'van-checkbox-group': CheckboxGroup - } -}; ``` ### 代码演示 diff --git a/docs/examples-docs/datetime-picker.md b/docs/examples-docs/datetime-picker.md index e3d33c552..dd4973ea6 100644 --- a/docs/examples-docs/datetime-picker.md +++ b/docs/examples-docs/datetime-picker.md @@ -5,15 +5,16 @@ export default { minHour: 10, maxHour: 20, minDate: new Date(), - currentDate1: null, + maxDate: new Date(2019, 10, 1), + currentDate1: new Date(2018, 0, 1), currentDate2: null, currentDate3: null }; }, methods: { - handlePickerChange(picker, values) { - console.log(values); + handlePickerChange(picker) { + console.log(picker); }, handlePickerCancel() { console.log('picker cancel'); @@ -25,38 +26,15 @@ export default { }; -## Datetime Picker 时间选择 +## DatetimePicker 时间选择 ### 使用指南 - -如果你已经按照快速上手中引入了整个`vant`,以下**组件注册**就可以忽略了,因为你已经全局注册了`vant`中的全部组件。 - -#### 全局注册 - -你可以在全局注册`Radio`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`Radio`组件了: - -```js -import Vue from 'vue'; +``` javascript import { DatetimePicker } from 'vant'; Vue.component(DatetimePicker.name, DatetimePicker); ``` -#### 局部注册 - -如果你只是想在某个组件中使用,你可以在对应组件中注册`DatetimePicker`组件,这样只能在你注册的组件中使用`DatetimePicker`: - -```js -import { DatetimePicker } from 'vant'; - -export default { - components: { - 'van-datetime-picker': DatetimePicker - } -}; -``` - - ### 代码演示 #### 基础用法 @@ -66,10 +44,10 @@ export default { @@ -80,13 +58,14 @@ export default { minHour: 10, maxHour: 20, minDate: new Date(), - currentDate: null + maxDate: new Date(2019, 10, 1), + currentDate: new Date(2018, 0, 1) }; }, methods: { - handlePickerChange(picker, values) { - picker.setColumnValues(1, citys[values[0]]); + handlePickerChange(picker) { + console.log(picker); } } }; @@ -101,7 +80,6 @@ export default { + +export default { + data() { + return { + items: [{ + text: '所有城市', + children: [{ + text: '杭州', + id: 1001 + }, { + text: '温州', + id: 1002 + }, { + text: '海南', + id: 1100 + }, { + text: '宁波', + id: 1003 + }, { + text: '义乌', + id: 1004 + }, { + text: '无锡', + id: 1011 + }, { + text: '常州', + id: 1012 + }, { + text: '大连', + id: 1031 + }, { + text: '诸暨', + id: 1005 + }] + }, { + text: '浙江', + children: [{ + text: '杭州', + id: 1001 + }, { + text: '温州', + id: 1002 + }, { + text: '宁波', + id: 1003 + }, { + text: '义乌', + id: 1004 + }] + }, { + text: '江苏', + children: [{ + text: '无锡', + id: 1011 + }, { + text: '常州', + id: 1012 + }] + }], + mainActiveIndex: 0, + activeId: 1001 + }; + }, + methods: { + onNavClick(index) { + this.mainActiveIndex = index; + }, + onItemClick(data) { + console.log(data); + this.activeId = data.id; + } + } +} + + +## DeepSelect 分类选择组件 + +### 使用指南 +``` javascript +import { DeepSelect } from 'vant'; + +Vue.component(DeepSelect.name, DeepSelect); +``` + +### 代码演示 + +#### 基础用法 + +:::demo 基础用法 +```html + +``` + +```javascript +export default { + data() { + return { + items: items, + // 左侧高亮元素的index + mainActiveIndex: 0, + // 被选中元素的id + activeId: 1001 + }; + }, + methods: { + onNavClick(index) { + this.mainActiveIndex = index; + }, + onItemClick(data) { + console.log(data); + this.activeId = data.id; + } + } +} + +``` +::: + +### API + +#### 传入参数 + +| 参数 | 说明 | 类型 | 默认值 | 必须 | +|-----------|-----------|-----------|-------------|-------------| +| items | 分类显示所需的数据,具体数据结构可看 数据结构 | Array | [] | | +| mainActiveIndex | 左侧导航高亮的索引 | Number | 0 | | +| activeId | 右侧选择项,高亮的数据id | Number | 0 | | + +#### 事件 +| 事件名 | 说明 | 参数 | +|-----------|-----------|-----------| +| navclick | 左侧导航点击时,触发的事件 | index:被点击的导航的索引 | +| itemclick | 右侧选择项被点击时,会触发的事件 | data: 该点击项的数据 | + +### 数据格式 +#### items 分类显示所需数据的数据结构 +`items` 整体为一个数组,数组内包含一系列描述分类的 object。 + +每个分类里,text表示当前分类的名称。children 表示分类里的可选项,为数组结构,id被用来唯一标识每个选项 +```javascript +[ + { + // 导航名称 + text: '所有城市', + // 该导航下所有的可选项 + children: [ + { + // 可选项的名称 + text: '温州', + // 可选项的id,高亮的时候是根据id是否和选中的id是否相同进行判断的 + id: 1002 + }, + { + // 可选项的名称 + text: '杭州', + // 可选项的id,高亮的时候是根据id是否和选中的id是否相同进行判断的 + id: 1001 + } + ] + } +] +``` diff --git a/docs/examples-docs/dialog.md b/docs/examples-docs/dialog.md index 1faa20519..cb71eacc0 100644 --- a/docs/examples-docs/dialog.md +++ b/docs/examples-docs/dialog.md @@ -7,38 +7,31 @@ + +### 使用指南 +``` javascript +import { ExpressWay } from 'vant'; + +Vue.component(ExpressWay.name, ExpressWay); +``` + +### 代码演示 + +#### 基础用法 + +:::demo 基础用法 +```html + diff --git a/packages/datetime-picker/package.json b/packages/datetime-picker/package.json deleted file mode 100644 index 7b747cbdf..000000000 --- a/packages/datetime-picker/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "@youzan/van-datetime-picker", - "version": "0.0.1", - "description": "datetime picker component", - "main": "./index.js", - "author": "niunai ", - "license": "MIT", - "devDependencies": {}, - "dependencies": {} -} diff --git a/packages/deep-select/index.vue b/packages/deep-select/index.vue new file mode 100644 index 000000000..410b6ae86 --- /dev/null +++ b/packages/deep-select/index.vue @@ -0,0 +1,85 @@ + + + diff --git a/packages/dialog/CHANGELOG.md b/packages/dialog/CHANGELOG.md deleted file mode 100644 index e88c472b3..000000000 --- a/packages/dialog/CHANGELOG.md +++ /dev/null @@ -1,8 +0,0 @@ -## 0.0.2 (2017-01-20) - -* 改了bug A -* 加了功能B - -## 0.0.1 (2017-01-10) - -* 第一版 diff --git a/packages/dialog/README.md b/packages/dialog/README.md deleted file mode 100644 index 4c6172563..000000000 --- a/packages/dialog/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# @youzan/<%= name %> - -!!! 请在此处填写你的文档最简单描述 !!! - -[![version][version-image]][download-url] -[![download][download-image]][download-url] - -[version-image]: http://npm.qima-inc.com/badge/v/@youzan/<%= name %>.svg?style=flat-square -[download-image]: http://npm.qima-inc.com/badge/d/@youzan/<%= name %>.svg?style=flat-square -[download-url]: http://npm.qima-inc.com/package/@youzan/<%= name %> - -## Demo - -## Usage - -## API - -| 参数 | 说明 | 类型 | 默认值 | 可选值 | -|-----------|-----------|-----------|-------------|-------------| -| className | 自定义额外类名 | string | '' | '' | - - - - -## License -[MIT](https://opensource.org/licenses/MIT) diff --git a/packages/dialog/dialog.vue b/packages/dialog/dialog.vue new file mode 100644 index 000000000..7aec18626 --- /dev/null +++ b/packages/dialog/dialog.vue @@ -0,0 +1,78 @@ + + + diff --git a/packages/dialog/index.js b/packages/dialog/index.js index cb8dcd8d5..02df39c96 100644 --- a/packages/dialog/index.js +++ b/packages/dialog/index.js @@ -1,3 +1,62 @@ -import Dialog from './src/dialog.js'; +import Vue from 'vue'; +import DialogComponent from './dialog'; + +let instance; + +const defaultConfig = { + value: true, + title: '', + message: '', + showCancelButton: false, + closeOnClickOverlay: false, + callback: action => { + instance[action === 'confirm' ? 'resolve' : 'reject'](action); + } +}; + +const initInstance = () => { + const DialogConstructor = Vue.extend(DialogComponent); + instance = new DialogConstructor({ + el: document.createElement('div') + }); + + instance.$on('input', value => { + instance.value = value; + }); + + document.body.appendChild(instance.$el); +}; + +const Dialog = options => { + return new Promise((resolve, reject) => { + if (!instance) { + initInstance(); + } + + Object.assign(instance, { + resolve, + reject, + ...options + }); + }); +}; + +Dialog.alert = options => Dialog({ + ...defaultConfig, + ...options +}); + +Dialog.confirm = options => Dialog({ + ...defaultConfig, + showCancelButton: true, + ...options +}); + +Dialog.close = () => { + instance.value = false; +}; export default Dialog; +export { + Dialog +}; diff --git a/packages/dialog/package.json b/packages/dialog/package.json deleted file mode 100644 index dbbc335ff..000000000 --- a/packages/dialog/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "@youzan/van-dialog", - "version": "0.0.1", - "description": "dialog component", - "main": "./index.js", - "author": "zhangmin ", - "license": "MIT", - "devDependencies": {}, - "dependencies": {} -} diff --git a/packages/dialog/src/dialog.js b/packages/dialog/src/dialog.js deleted file mode 100644 index 962d8a950..000000000 --- a/packages/dialog/src/dialog.js +++ /dev/null @@ -1,99 +0,0 @@ -import Vue from 'vue'; -import Dialog from './dialog.vue'; -import merge from 'src/utils/merge'; - -const DialogConstructor = Vue.extend(Dialog); - -let currentDialog; -let instance; -let dialogQueue = []; - -const defaultCallback = action => { - /* istanbul ignore else */ - if (currentDialog) { - if (currentDialog.resolve && action === 'confirm') { - currentDialog.resolve(action); - } else if (currentDialog.reject && action === 'cancel') { - currentDialog.reject(action); - } - } -}; - -const initInstance = () => { - instance = new DialogConstructor({ - el: document.createElement('div') - }); - - instance.callback = defaultCallback; -}; - -const showNextDialog = () => { - if (!instance) { - initInstance(); - } - - /* istanbul ignore else */ - if (!instance.value && dialogQueue.length > 0) { - currentDialog = dialogQueue.shift(); - - const options = currentDialog.options; - - for (const prop in options) { - /* istanbul ignore else */ - if (options.hasOwnProperty(prop)) { - instance[prop] = options[prop]; - } - } - - if (options.callback === undefined) { - instance.callback = defaultCallback; - } - - document.body.appendChild(instance.$el); - - Vue.nextTick(() => { - instance.value = true; - }); - } -}; - -var DialogBox = options => { - return new Promise((resolve, reject) => { // eslint-disable-line - dialogQueue.push({ - options: merge({}, options), - callback: options.callback, - resolve: resolve, - reject: reject - }); - - showNextDialog(); - }); -}; - -DialogBox.alert = function(options) { - return DialogBox(merge({ - type: 'alert', - title: '', - message: '', - closeOnClickOverlay: false, - showCancelButton: false - }, options)); -}; - -DialogBox.confirm = function(options) { - return DialogBox(merge({ - type: 'confirm', - title: '', - message: '', - closeOnClickOverlay: true, - showCancelButton: true - }, options)); -}; - -DialogBox.close = function() { - instance.value = false; - dialogQueue = []; - currentDialog = null; -}; - -export default DialogBox; diff --git a/packages/dialog/src/dialog.vue b/packages/dialog/src/dialog.vue deleted file mode 100644 index 47849b3eb..000000000 --- a/packages/dialog/src/dialog.vue +++ /dev/null @@ -1,85 +0,0 @@ - - - diff --git a/packages/express-way/Option.vue b/packages/express-way/Option.vue new file mode 100644 index 000000000..c29521dfa --- /dev/null +++ b/packages/express-way/Option.vue @@ -0,0 +1,32 @@ + + + diff --git a/packages/express-way/index.vue b/packages/express-way/index.vue new file mode 100644 index 000000000..fcc72da4a --- /dev/null +++ b/packages/express-way/index.vue @@ -0,0 +1,100 @@ + + + diff --git a/packages/field/CHANGELOG.md b/packages/field/CHANGELOG.md deleted file mode 100644 index e88c472b3..000000000 --- a/packages/field/CHANGELOG.md +++ /dev/null @@ -1,8 +0,0 @@ -## 0.0.2 (2017-01-20) - -* 改了bug A -* 加了功能B - -## 0.0.1 (2017-01-10) - -* 第一版 diff --git a/packages/field/README.md b/packages/field/README.md deleted file mode 100644 index 4c6172563..000000000 --- a/packages/field/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# @youzan/<%= name %> - -!!! 请在此处填写你的文档最简单描述 !!! - -[![version][version-image]][download-url] -[![download][download-image]][download-url] - -[version-image]: http://npm.qima-inc.com/badge/v/@youzan/<%= name %>.svg?style=flat-square -[download-image]: http://npm.qima-inc.com/badge/d/@youzan/<%= name %>.svg?style=flat-square -[download-url]: http://npm.qima-inc.com/package/@youzan/<%= name %> - -## Demo - -## Usage - -## API - -| 参数 | 说明 | 类型 | 默认值 | 可选值 | -|-----------|-----------|-----------|-------------|-------------| -| className | 自定义额外类名 | string | '' | '' | - - - - -## License -[MIT](https://opensource.org/licenses/MIT) diff --git a/packages/field/index.js b/packages/field/index.js deleted file mode 100644 index 391f5272c..000000000 --- a/packages/field/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import Field from './src/field'; - -export default Field; diff --git a/packages/field/src/field.vue b/packages/field/index.vue similarity index 67% rename from packages/field/src/field.vue rename to packages/field/index.vue index f2c542e27..c2f32d3e9 100644 --- a/packages/field/src/field.vue +++ b/packages/field/index.vue @@ -9,7 +9,8 @@ 'van-field--disabled': disabled, 'van-field--error': error, 'van-field--border': border, - 'van-field--autosize': autosize + 'van-field--autosize': autosize, + 'van-field--has-icon': showIcon }">