From 9644047dc7e551c98628a59218c51b3a9511d401 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sun, 23 Aug 2020 14:31:03 +0800 Subject: [PATCH] refactor(ActionBar): use setup --- src/action-bar-button/index.js | 66 ++++++++++++++-------------------- src/action-bar-icon/index.js | 46 ++++++++++++------------ src/action-bar/index.js | 8 ++--- 3 files changed, 54 insertions(+), 66 deletions(-) diff --git a/src/action-bar-button/index.js b/src/action-bar-button/index.js index 77d819131..f145032ad 100644 --- a/src/action-bar-button/index.js +++ b/src/action-bar-button/index.js @@ -18,47 +18,35 @@ export default createComponent({ disabled: Boolean, }, - emits: ['click'], + setup(props, { slots }) { + return (vm) => { + const { type, icon, text, color, loading, disabled } = props; - computed: { - isFirst() { - const prev = this.parent && this.parent.children[this.index - 1]; - return !prev || prev.$options.name !== this.$options.name; - }, + const { parent } = vm; + const { name } = vm.$options; + const prev = parent && parent.children[vm.index - 1]; + const next = parent && parent.children[vm.index + 1]; + const last = !next || name !== next.$options.name; + const first = !prev || name !== prev.$options.name; - isLast() { - const next = this.parent && this.parent.children[this.index + 1]; - return !next || next.$options.name !== this.$options.name; - }, - }, + const onClick = () => { + route(vm.$router, vm); + }; - methods: { - onClick(event) { - this.$emit('click', event); - route(this.$router, this); - }, - }, - - render() { - return ( - - ); + return ( + + ); + }; }, }); diff --git a/src/action-bar-icon/index.js b/src/action-bar-icon/index.js index c47dee5bf..170bebac0 100644 --- a/src/action-bar-icon/index.js +++ b/src/action-bar-icon/index.js @@ -19,42 +19,42 @@ export default createComponent({ iconClass: null, }, - emits: ['click'], + setup(props, { slots }) { + function genIcon() { + const { dot, badge, icon, color, iconClass } = props; - methods: { - onClick(event) { - this.$emit('click', event); - route(this.$router, this); - }, - - genIcon() { - if (this.$slots.icon) { + if (slots.icon) { return (
- {this.$slots.icon()} - + {slots.icon()} +
); } return ( ); - }, - }, + } - render() { - return ( -
- {this.genIcon()} - {this.$slots.default ? this.$slots.default() : this.text} + return (vm) => ( +
{ + route(vm.$router, vm); + }} + > + {genIcon()} + {slots.default ? slots.default() : props.text}
); }, diff --git a/src/action-bar/index.js b/src/action-bar/index.js index 172215075..23c4843e0 100644 --- a/src/action-bar/index.js +++ b/src/action-bar/index.js @@ -13,10 +13,10 @@ export default createComponent({ }, }, - render() { - return ( -
- {this.$slots.default?.()} + setup(props, { slots }) { + return () => ( +
+ {slots.default?.()}
); },