diff --git a/src/grid-item/index.js b/src/grid-item/index.js index e209337ce..d98585982 100644 --- a/src/grid-item/index.js +++ b/src/grid-item/index.js @@ -1,10 +1,13 @@ +import { computed } from 'vue'; + // Utils import { createNamespace, addUnit } from '../utils'; import { BORDER } from '../utils/constant'; -import { route, routeProps } from '../composition/use-route'; +import { GRID_KEY } from '../grid'; -// Mixins -import { ChildrenMixin } from '../mixins/relation'; +// Composition +import { useParent } from '../composition/use-relation'; +import { useRoute, routeProps } from '../composition/use-route'; // Components import Icon from '../icon'; @@ -13,24 +16,22 @@ import Badge from '../badge'; const [createComponent, bem] = createNamespace('grid-item'); export default createComponent({ - mixins: [ChildrenMixin('vanGrid')], - props: { ...routeProps, dot: Boolean, text: String, icon: String, - iconPrefix: String, badge: [Number, String], + iconPrefix: String, }, - emits: ['click'], + setup(props, { slots }) { + const { parent, index } = useParent(GRID_KEY); + const route = useRoute(); - computed: { - style() { - const { square, gutter, columnNum } = this.parent; + const rootStyle = computed(() => { + const { square, gutter, columnNum } = parent.props; const percent = `${100 / columnNum}%`; - const style = { flexBasis: percent, }; @@ -41,111 +42,103 @@ export default createComponent({ const gutterValue = addUnit(gutter); style.paddingRight = gutterValue; - if (this.index >= columnNum) { + if (index.value >= columnNum) { style.marginTop = gutterValue; } } return style; - }, + }); - contentStyle() { - const { square, gutter } = this.parent; + const contentStyle = computed(() => { + const { square, gutter } = parent.props; if (square && gutter) { const gutterValue = addUnit(gutter); - return { right: gutterValue, bottom: gutterValue, height: 'auto', }; } - }, - }, + }); - methods: { - onClick(event) { - this.$emit('click', event); - route(this.$router, this); - }, - - genIcon() { - if (this.$slots.icon) { + const renderIcon = () => { + if (slots.icon) { return (