Commit ed91d9b0c7d3dcbf2cbc08f4cc53ab950e68f3e2

Authored by 梁灏
1 parent 345c6863

update Select

support IE9
examples/routers/select.vue
... ... @@ -193,31 +193,51 @@
193 193  
194 194 <template>
195 195 <div>
196   - <i-select v-model="d" filterable style="width: 200px" multiple>
197   - <i-option :key="e" v-for="e in uList" :value="e.id" :label="e.name">
198   - <span>{{ e.name }}</span>
199   - <span style="float:right;color:#ccc">{{ e.id }}</span>
200   - </i-option>
201   - </i-select>
202   - <p>{{d}}</p>
203   - <i-button type="primary" v-on:click="clear">清空</i-button>
  196 + <Select v-model="model1" style="width:200px">
  197 + <Option v-for="item in cityList" :value="item.value" :key="item">{{ item.label }}</Option>
  198 + </Select>
  199 + {{ model1 }}
  200 + <Button @click="set">set</Button>
  201 + <Button @click="add">add</Button>
  202 + <Button @click="remove">remove</Button>
204 203 </div>
205 204 </template>
206 205 <script>
207 206 export default {
208 207 data () {
209 208 return {
210   - d: [],
211   - uList : [
212   - {id:1,name:"中国"},
213   - {id:2,name:"美国"},
214   - {id:3,name:"韩国"}
215   - ]
  209 + cityList: [
  210 + {
  211 + value: 'beijing',
  212 + label: '北京市'
  213 + },
  214 + {
  215 + value: 'shanghai',
  216 + label: '上海市'
  217 + },
  218 + {
  219 + value: 'shenzhen',
  220 + label: '深圳市'
  221 + }
  222 + ],
  223 + model1: ''
216 224 }
217 225 },
218 226 methods: {
219 227 clear(){
220 228 this.d = [];
  229 + },
  230 + set () {
  231 + this.model1 = 'shenzhen';
  232 + },
  233 + add () {
  234 + this.cityList.push({
  235 + value: 'chongqing',
  236 + label: '重庆市'
  237 + });
  238 + },
  239 + remove () {
  240 + this.cityList.splice(0, 1);
221 241 }
222 242 }
223 243 }
... ...
src/components/select/option.vue
... ... @@ -65,12 +65,16 @@
65 65 },
66 66 mounted () {
67 67 this.searchLabel = this.$el.innerHTML;
  68 + this.dispatch('iSelect', 'append');
68 69 this.$on('on-select-close', () => {
69 70 this.isFocus = false;
70 71 });
71 72 this.$on('on-query-change', (val) => {
72 73 this.queryChange(val);
73 74 });
  75 + },
  76 + beforeDestroy () {
  77 + this.dispatch('iSelect', 'remove');
74 78 }
75 79 };
76 80 </script>
... ...
src/components/select/select.vue
... ... @@ -36,7 +36,7 @@
36 36 import Icon from '../icon';
37 37 import Drop from './dropdown.vue';
38 38 import clickoutside from '../../directives/clickoutside';
39   - import { oneOf, MutationObserver, findComponentDownward } from '../../utils/assist';
  39 + import { oneOf, findComponentDownward } from '../../utils/assist';
40 40 import { t } from '../../locale';
41 41 import Emitter from '../../mixins/emitter';
42 42  
... ... @@ -506,22 +506,16 @@
506 506 this.updateOptions(true);
507 507 document.addEventListener('keydown', this.handleKeydown);
508 508  
509   - // watch slot changed
510   - // todo 在 child 的 mounted 和 beforeDestroy 里处理
511   - if (MutationObserver) {
512   - this.observer = new MutationObserver(() => {
513   - this.modelToQuery();
514   - this.slotChange();
515   - this.updateOptions(true, true);
516   - });
517   -
518   - this.observer.observe(this.$refs.options, {
519   -// attributes: true,
520   - childList: true,
521   - characterData: true,
522   - subtree: true
523   - });
524   - }
  509 + this.$on('append', () => {
  510 + this.modelToQuery();
  511 + this.slotChange();
  512 + this.updateOptions(true, true);
  513 + });
  514 + this.$on('remove', () => {
  515 + this.modelToQuery();
  516 + this.slotChange();
  517 + this.updateOptions(true, true);
  518 + });
525 519  
526 520 this.$on('on-select-selected', (value) => {
527 521 if (this.model === value) {
... ... @@ -556,9 +550,6 @@
556 550 },
557 551 beforeDestroy () {
558 552 document.removeEventListener('keydown', this.handleKeydown);
559   - if (this.observer) {
560   - this.observer.disconnect();
561   - }
562 553 },
563 554 watch: {
564 555 value (val) {
... ...