From d32c9486569853f28ed03656ea86017e7ca4825d Mon Sep 17 00:00:00 2001 From: FairyEver <1711467488@qq.com> Date: Mon, 6 Jul 2020 10:42:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:sparkles:=20=E7=AE=80=E5=8C=96=20d?= =?UTF-8?q?2-container=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/d2-container/index.js | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/components/d2-container/index.js b/src/components/d2-container/index.js index ccde1ade..ced6e2ac 100644 --- a/src/components/d2-container/index.js +++ b/src/components/d2-container/index.js @@ -1,12 +1,15 @@ -// 组件 -import d2ContainerFull from './components/d2-container-full.vue' -import d2ContainerFullBs from './components/d2-container-full-bs.vue' -import d2ContainerGhost from './components/d2-container-ghost.vue' -import d2ContainerGhostBs from './components/d2-container-ghost-bs.vue' -import d2ContainerCard from './components/d2-container-card.vue' -import d2ContainerCardBs from './components/d2-container-card-bs.vue' +import { get } from 'lodash' import d2Source from './components/d2-source.vue' +const containers = { + full: () => import('./components/d2-container-full.vue'), + fullbs: () => import('./components/d2-container-full-bs.vue'), + ghost: () => import('./components/d2-container-ghost.vue'), + ghostbs: () => import('./components/d2-container-ghost-bs.vue'), + card: () => import('./components/d2-container-card.vue'), + cardbs: () => import('./components/d2-container-card-bs.vue') +} + export default { name: 'd2-container', props: { @@ -26,15 +29,7 @@ export default { computed: { // 始终返回渲染组件 component () { - if (this.type === 'card' && !this.betterScroll) return d2ContainerCard - if (this.type === 'card' && this.betterScroll) return d2ContainerCardBs - if (this.type === 'ghost' && !this.betterScroll) return d2ContainerGhost - if (this.type === 'ghost' && this.betterScroll) return d2ContainerGhostBs - if (this.type === 'full' && !this.betterScroll) return d2ContainerFull - if (this.type === 'full' && this.betterScroll) return d2ContainerFullBs - else { - return 'div' - } + return get(containers, `${this.type}${this.betterScroll ? 'bs' : ''}`, 'div') } }, render (h) {