Commit ed91d9b0c7d3dcbf2cbc08f4cc53ab950e68f3e2
1 parent
345c6863
update Select
support IE9
Showing
3 changed files
with
49 additions
and
34 deletions
Show diff stats
examples/routers/select.vue
| @@ -193,31 +193,51 @@ | @@ -193,31 +193,51 @@ | ||
| 193 | 193 | ||
| 194 | <template> | 194 | <template> |
| 195 | <div> | 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 | </div> | 203 | </div> |
| 205 | </template> | 204 | </template> |
| 206 | <script> | 205 | <script> |
| 207 | export default { | 206 | export default { |
| 208 | data () { | 207 | data () { |
| 209 | return { | 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 | methods: { | 226 | methods: { |
| 219 | clear(){ | 227 | clear(){ |
| 220 | this.d = []; | 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,12 +65,16 @@ | ||
| 65 | }, | 65 | }, |
| 66 | mounted () { | 66 | mounted () { |
| 67 | this.searchLabel = this.$el.innerHTML; | 67 | this.searchLabel = this.$el.innerHTML; |
| 68 | + this.dispatch('iSelect', 'append'); | ||
| 68 | this.$on('on-select-close', () => { | 69 | this.$on('on-select-close', () => { |
| 69 | this.isFocus = false; | 70 | this.isFocus = false; |
| 70 | }); | 71 | }); |
| 71 | this.$on('on-query-change', (val) => { | 72 | this.$on('on-query-change', (val) => { |
| 72 | this.queryChange(val); | 73 | this.queryChange(val); |
| 73 | }); | 74 | }); |
| 75 | + }, | ||
| 76 | + beforeDestroy () { | ||
| 77 | + this.dispatch('iSelect', 'remove'); | ||
| 74 | } | 78 | } |
| 75 | }; | 79 | }; |
| 76 | </script> | 80 | </script> |
src/components/select/select.vue
| @@ -36,7 +36,7 @@ | @@ -36,7 +36,7 @@ | ||
| 36 | import Icon from '../icon'; | 36 | import Icon from '../icon'; |
| 37 | import Drop from './dropdown.vue'; | 37 | import Drop from './dropdown.vue'; |
| 38 | import clickoutside from '../../directives/clickoutside'; | 38 | import clickoutside from '../../directives/clickoutside'; |
| 39 | - import { oneOf, MutationObserver, findComponentDownward } from '../../utils/assist'; | 39 | + import { oneOf, findComponentDownward } from '../../utils/assist'; |
| 40 | import { t } from '../../locale'; | 40 | import { t } from '../../locale'; |
| 41 | import Emitter from '../../mixins/emitter'; | 41 | import Emitter from '../../mixins/emitter'; |
| 42 | 42 | ||
| @@ -506,22 +506,16 @@ | @@ -506,22 +506,16 @@ | ||
| 506 | this.updateOptions(true); | 506 | this.updateOptions(true); |
| 507 | document.addEventListener('keydown', this.handleKeydown); | 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 | this.$on('on-select-selected', (value) => { | 520 | this.$on('on-select-selected', (value) => { |
| 527 | if (this.model === value) { | 521 | if (this.model === value) { |
| @@ -556,9 +550,6 @@ | @@ -556,9 +550,6 @@ | ||
| 556 | }, | 550 | }, |
| 557 | beforeDestroy () { | 551 | beforeDestroy () { |
| 558 | document.removeEventListener('keydown', this.handleKeydown); | 552 | document.removeEventListener('keydown', this.handleKeydown); |
| 559 | - if (this.observer) { | ||
| 560 | - this.observer.disconnect(); | ||
| 561 | - } | ||
| 562 | }, | 553 | }, |
| 563 | watch: { | 554 | watch: { |
| 564 | value (val) { | 555 | value (val) { |