From ed91d9b0c7d3dcbf2cbc08f4cc53ab950e68f3e2 Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Thu, 30 Mar 2017 11:52:36 +0800 Subject: [PATCH] update Select --- examples/routers/select.vue | 48 ++++++++++++++++++++++++++++++++++-------------- src/components/select/option.vue | 4 ++++ src/components/select/select.vue | 31 +++++++++++-------------------- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/examples/routers/select.vue b/examples/routers/select.vue index 813b530..a97b620 100644 --- a/examples/routers/select.vue +++ b/examples/routers/select.vue @@ -193,31 +193,51 @@ diff --git a/src/components/select/select.vue b/src/components/select/select.vue index 21034b0..f7b81ca 100644 --- a/src/components/select/select.vue +++ b/src/components/select/select.vue @@ -36,7 +36,7 @@ import Icon from '../icon'; import Drop from './dropdown.vue'; import clickoutside from '../../directives/clickoutside'; - import { oneOf, MutationObserver, findComponentDownward } from '../../utils/assist'; + import { oneOf, findComponentDownward } from '../../utils/assist'; import { t } from '../../locale'; import Emitter from '../../mixins/emitter'; @@ -506,22 +506,16 @@ this.updateOptions(true); document.addEventListener('keydown', this.handleKeydown); - // watch slot changed - // todo 在 child 的 mounted 和 beforeDestroy 里处理 - if (MutationObserver) { - this.observer = new MutationObserver(() => { - this.modelToQuery(); - this.slotChange(); - this.updateOptions(true, true); - }); - - this.observer.observe(this.$refs.options, { -// attributes: true, - childList: true, - characterData: true, - subtree: true - }); - } + this.$on('append', () => { + this.modelToQuery(); + this.slotChange(); + this.updateOptions(true, true); + }); + this.$on('remove', () => { + this.modelToQuery(); + this.slotChange(); + this.updateOptions(true, true); + }); this.$on('on-select-selected', (value) => { if (this.model === value) { @@ -556,9 +550,6 @@ }, beforeDestroy () { document.removeEventListener('keydown', this.handleKeydown); - if (this.observer) { - this.observer.disconnect(); - } }, watch: { value (val) { -- libgit2 0.21.4