update Select

support IE9
This commit is contained in:
梁灏 2017-03-30 11:52:36 +08:00
parent 345c6863bf
commit ed91d9b0c7
3 changed files with 49 additions and 34 deletions

View file

@ -193,31 +193,51 @@
<template> <template>
<div> <div>
<i-select v-model="d" filterable style="width: 200px" multiple> <Select v-model="model1" style="width:200px">
<i-option :key="e" v-for="e in uList" :value="e.id" :label="e.name"> <Option v-for="item in cityList" :value="item.value" :key="item">{{ item.label }}</Option>
<span>{{ e.name }}</span> </Select>
<span style="float:right;color:#ccc">{{ e.id }}</span> {{ model1 }}
</i-option> <Button @click="set">set</Button>
</i-select> <Button @click="add">add</Button>
<p>{{d}}</p> <Button @click="remove">remove</Button>
<i-button type="primary" v-on:click="clear">清空</i-button>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
data () { data () {
return { return {
d: [], cityList: [
uList : [ {
{id:1,name:"中国"}, value: 'beijing',
{id:2,name:"美国"}, label: '北京市'
{id:3,name:"韩国"} },
] {
value: 'shanghai',
label: '上海市'
},
{
value: 'shenzhen',
label: '深圳市'
}
],
model1: ''
} }
}, },
methods: { methods: {
clear(){ clear(){
this.d = []; this.d = [];
},
set () {
this.model1 = 'shenzhen';
},
add () {
this.cityList.push({
value: 'chongqing',
label: '重庆市'
});
},
remove () {
this.cityList.splice(0, 1);
} }
} }
} }

View file

@ -65,12 +65,16 @@
}, },
mounted () { mounted () {
this.searchLabel = this.$el.innerHTML; this.searchLabel = this.$el.innerHTML;
this.dispatch('iSelect', 'append');
this.$on('on-select-close', () => { this.$on('on-select-close', () => {
this.isFocus = false; this.isFocus = false;
}); });
this.$on('on-query-change', (val) => { this.$on('on-query-change', (val) => {
this.queryChange(val); this.queryChange(val);
}); });
},
beforeDestroy () {
this.dispatch('iSelect', 'remove');
} }
}; };
</script> </script>

View file

@ -36,7 +36,7 @@
import Icon from '../icon'; import Icon from '../icon';
import Drop from './dropdown.vue'; import Drop from './dropdown.vue';
import clickoutside from '../../directives/clickoutside'; import clickoutside from '../../directives/clickoutside';
import { oneOf, MutationObserver, findComponentDownward } from '../../utils/assist'; import { oneOf, findComponentDownward } from '../../utils/assist';
import { t } from '../../locale'; import { t } from '../../locale';
import Emitter from '../../mixins/emitter'; import Emitter from '../../mixins/emitter';
@ -506,22 +506,16 @@
this.updateOptions(true); this.updateOptions(true);
document.addEventListener('keydown', this.handleKeydown); document.addEventListener('keydown', this.handleKeydown);
// watch slot changed this.$on('append', () => {
// todo child mounted beforeDestroy this.modelToQuery();
if (MutationObserver) { this.slotChange();
this.observer = new MutationObserver(() => { this.updateOptions(true, true);
this.modelToQuery(); });
this.slotChange(); this.$on('remove', () => {
this.updateOptions(true, true); this.modelToQuery();
}); this.slotChange();
this.updateOptions(true, true);
this.observer.observe(this.$refs.options, { });
// attributes: true,
childList: true,
characterData: true,
subtree: true
});
}
this.$on('on-select-selected', (value) => { this.$on('on-select-selected', (value) => {
if (this.model === value) { if (this.model === value) {
@ -556,9 +550,6 @@
}, },
beforeDestroy () { beforeDestroy () {
document.removeEventListener('keydown', this.handleKeydown); document.removeEventListener('keydown', this.handleKeydown);
if (this.observer) {
this.observer.disconnect();
}
}, },
watch: { watch: {
value (val) { value (val) {