From a364634a349844820d55f414fb3a9c80d15e007d Mon Sep 17 00:00:00 2001 From: cookfront Date: Fri, 31 Mar 2017 10:56:12 +0800 Subject: [PATCH] fix build --- docs/examples-docs/tab.md | 126 +++++++++++++++++++++------- packages/tab/src/tab.vue | 10 +-- packages/tab/src/tabs.vue | 50 ++++++----- packages/zanui-css/scripts/build.sh | 2 +- packages/zanui-css/src/tab.css | 4 +- 5 files changed, 134 insertions(+), 58 deletions(-) diff --git a/docs/examples-docs/tab.md b/docs/examples-docs/tab.md index d0424c8c8..5b9c2a7c5 100644 --- a/docs/examples-docs/tab.md +++ b/docs/examples-docs/tab.md @@ -1,4 +1,3 @@ - @@ -36,7 +51,43 @@ export default { ## Tab 标签 -### 基础用法 +### 使用指南 + +如果你已经按照[快速上手](/vue/component/quickstart)中引入了整个`ZanUI`,以下**组件注册**就可以忽略了,因为你已经全局注册了`ZanUI`中的全部组件。 + +#### 全局注册 + +你可以在全局注册`Tab`组件,比如页面的主文件(`index.js`,`main.js`),这样页面任何地方都可以直接使用`Tab`组件了: + +```js +import Vue from 'vue'; +import { Tab, Tabs } from '@youzan/zanui-vue'; +import '@youzan/zanui-vue/lib/zanui-css/tab.css'; + +Vue.component(Tab.name, Tab); +Vue.component(Tabs.name, Tabs); +``` + +#### 局部注册 + +如果你只是想在某个组件中使用,你可以在对应组件中注册`Tab`组件,这样只能在你注册的组件中使用`Tab`: + +```js +import { Tab, Tabs } from '@youzan/zanui-vue'; + +export default { + components: { + 'zan-tab': Tab, + 'zan-tabs': Tabs + } +}; +``` + +### 代码演示 + +#### 基础用法 + +默认情况下是启用第一个`tab`。 :::demo 基础用法 ```html @@ -50,17 +101,36 @@ export default { ``` ::: -### 禁用用法 +#### active特定tab -:::demo 禁用用法 +可以在`zan-tabs`上设置`active`为对应`tab`的索引(从0开始,即0代表第一个)即可激活对应`tab`。 + +:::demo 基础用法 ```html 内容一 - 内容二 + 内容二 内容三 内容四 内容五 +``` +::: + +#### 禁用tab + +在对应的`zan-tab`上设置`disabled`属性即可,如果需要监听禁用事件,可以监听`disabled`事件。 + +:::demo 禁用tab +```html + + 内容一 + 内容二 + 内容三 + 内容四 + 内容五 + + diff --git a/packages/tab/src/tabs.vue b/packages/tab/src/tabs.vue index af5f78f79..e56545632 100644 --- a/packages/tab/src/tabs.vue +++ b/packages/tab/src/tabs.vue @@ -1,18 +1,23 @@ @@ -30,11 +35,6 @@ type: { type: String, default: 'line' - }, - // nav的wrap的样式 - navclass: { - type: String, - default: '' } }, @@ -42,27 +42,28 @@ return { tabs: [], isReady: false, - switchActiveTabKey: +this.active + curActive: +this.active }; }, watch: { active(val) { - this.switchActiveTabKey = +val; + this.curActive = +val; } }, computed: { - classNames() { - return [`zan-tabs__nav--${this.type}`, `zan-tabs--col-${this.tabs.length}`, this.navclass]; - }, - + /** + * `type`为`line`时,tab下方的横线的样式 + */ navBarStyle() { - if (!this.isReady) return; - const tabKey = this.switchActiveTabKey; + if (!this.isReady || type !== 'line') return; + + const tabKey = this.curActive; const elem = this.$refs.tabkey[tabKey]; const offsetWidth = `${elem.offsetWidth || 0}px`; const offsetLeft = `${elem.offsetLeft || 0}px`; + return { width: offsetWidth, transform: `translate3d(${offsetLeft}, 0px, 0px)` @@ -71,13 +72,20 @@ }, methods: { + /** + * tab点击事件 + * + * @param {number} index tab在tabs中的索引 + * @param {Object} el tab的vue实例 + */ handleTabClick(index, el) { - if (el.disable) { - el.$emit('disable'); + if (el.disabled) { + el.$emit('disabled', index); return; } + this.$emit('click', index); - this.switchActiveTabKey = index; + this.curActive = index; } }, diff --git a/packages/zanui-css/scripts/build.sh b/packages/zanui-css/scripts/build.sh index d2aa91528..5d3ca5d89 100644 --- a/packages/zanui-css/scripts/build.sh +++ b/packages/zanui-css/scripts/build.sh @@ -14,7 +14,7 @@ command_exists () { fontname() { if command_exists superman ; then - echo "//b.yzcdn.cn$server_prefix/$(basename $basepath/../build/font/zanui-icon-*.$1)" + echo "https://b.yzcdn.cn$server_prefix/$(basename $basepath/../build/font/zanui-icon-*.$1)" else echo "$(abspath $basepath/../build/font/zanui-icon-*.$1)" fi diff --git a/packages/zanui-css/src/tab.css b/packages/zanui-css/src/tab.css index bc552a6be..b3fe3896a 100644 --- a/packages/zanui-css/src/tab.css +++ b/packages/zanui-css/src/tab.css @@ -53,9 +53,7 @@ border-radius: 2px; border: 1px solid #666666; overflow: hidden; - .zan-tabs__nav-bar { - display: none; - } + .zan-tab { color: #666666; line-height: 28px;