From f956d1ab3bdbbfd07d9d773936b221e8dd833712 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Mon, 17 Aug 2020 10:49:27 +0800 Subject: [PATCH] feat: migrate IndexBar component --- components.js | 2 ++ src/index-anchor/index.js | 6 ++++-- src/index-bar/index.js | 4 +++- vant.config.js | 16 ++++++++-------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/components.js b/components.js index f276ceefd..e66df7719 100644 --- a/components.js +++ b/components.js @@ -65,4 +65,6 @@ module.exports = [ 'swipe', 'swipe-item', 'image-preview', + 'index-bar', + 'index-anchor', ]; diff --git a/src/index-anchor/index.js b/src/index-anchor/index.js index 2852203a8..65ed1c9a1 100644 --- a/src/index-anchor/index.js +++ b/src/index-anchor/index.js @@ -39,7 +39,9 @@ export default createComponent({ }, mounted() { - this.height = this.$el.offsetHeight; + this.$nextTick(() => { + this.height = this.$el.offsetHeight; + }); }, methods: { @@ -57,7 +59,7 @@ export default createComponent({ style={this.anchorStyle} class={[bem({ sticky }), { [BORDER_BOTTOM]: sticky }]} > - {this.slots('default') || this.index} + {this.$slots.default ? this.$slots.default() : this.index} ); diff --git a/src/index-bar/index.js b/src/index-bar/index.js index aac5f009d..2e5d8ffe8 100644 --- a/src/index-bar/index.js +++ b/src/index-bar/index.js @@ -58,6 +58,8 @@ export default createComponent({ }, }, + emits: ['select'], + data() { return { activeAnchorIndex: null, @@ -245,7 +247,7 @@ export default createComponent({ > {Indexes} - {this.slots('default')} + {this.$slots.default?.()} ); }, diff --git a/vant.config.js b/vant.config.js index 12faec808..a42ec552e 100644 --- a/vant.config.js +++ b/vant.config.js @@ -290,10 +290,10 @@ module.exports = { path: 'grid', title: 'Grid 宫格', }, - // { - // path: 'index-bar', - // title: 'IndexBar 索引栏', - // }, + { + path: 'index-bar', + title: 'IndexBar 索引栏', + }, { path: 'nav-bar', title: 'NavBar 导航栏', @@ -624,10 +624,10 @@ module.exports = { path: 'grid', title: 'Grid', }, - // { - // path: 'index-bar', - // title: 'IndexBar', - // }, + { + path: 'index-bar', + title: 'IndexBar', + }, { path: 'nav-bar', title: 'NavBar',