Fix Option 'label' prop

pull/2/head
qingwei.li 2016-08-24 18:52:07 +08:00
parent 01f6b9da7d
commit 39bf244190
2 changed files with 10 additions and 9 deletions

View File

@ -6,7 +6,7 @@
v-show="queryPassed" v-show="queryPassed"
:class="{ 'selected': itemSelected, 'is-disabled': disabled, 'hover': parent.hoverIndex === index }"> :class="{ 'selected': itemSelected, 'is-disabled': disabled, 'hover': parent.hoverIndex === index }">
<slot> <slot>
<span>{{ label }}</span> <span>{{ currentLabel }}</span>
</slot> </slot>
</li> </li>
</template> </template>
@ -40,7 +40,8 @@
return { return {
index: -1, index: -1,
queryPassed: true, queryPassed: true,
hitState: false hitState: false,
currentLabel: this.label
}; };
}, },
@ -92,7 +93,7 @@
}, },
queryChange(query) { queryChange(query) {
this.queryPassed = new RegExp(query, 'i').test(this.label); this.queryPassed = new RegExp(query, 'i').test(this.currentLabel);
if (!this.queryPassed) { if (!this.queryPassed) {
this.parent.filteredOptionsCount--; this.parent.filteredOptionsCount--;
} }
@ -106,7 +107,7 @@
}, },
created() { created() {
this.label = this.label || ((typeof this.value === 'string' || typeof this.value === 'number') ? this.value : ''); this.currentLabel = this.currentLabel || ((typeof this.value === 'string' || typeof this.value === 'number') ? this.value : '');
this.parent.options.push(this); this.parent.options.push(this);
this.parent.optionsCount++; this.parent.optionsCount++;
this.parent.filteredOptionsCount++; this.parent.filteredOptionsCount++;

View File

@ -9,7 +9,7 @@
:hit="item.hitState" :hit="item.hitState"
type="primary" type="primary"
@click.native="deleteTag($event, item)" @click.native="deleteTag($event, item)"
close-transition>{{ item.label }}</el-tag> close-transition>{{ item.currentLabel }}</el-tag>
</transition-group> </transition-group>
<input <input
type="text" type="text"
@ -290,7 +290,7 @@
this.bottomOverflowBeforeHidden = this.selected.$el.getBoundingClientRect().bottom - this.$refs.popper.$el.getBoundingClientRect().bottom; this.bottomOverflowBeforeHidden = this.selected.$el.getBoundingClientRect().bottom - this.$refs.popper.$el.getBoundingClientRect().bottom;
} }
if (this.selected && this.selected.value) { if (this.selected && this.selected.value) {
this.selectedLabel = this.selected.label; this.selectedLabel = this.selected.currentLabel;
} }
} }
} else { } else {
@ -360,7 +360,7 @@
} }
} else { } else {
this.selected = option; this.selected = option;
this.selectedLabel = option.label; this.selectedLabel = option.currentLabel;
this.hoverIndex = option.index; this.hoverIndex = option.index;
} }
}, },
@ -402,12 +402,12 @@
handleOptionSelect(option) { handleOptionSelect(option) {
if (!this.multiple) { if (!this.multiple) {
this.selected = option; this.selected = option;
this.selectedLabel = option.label; this.selectedLabel = option.currentLabel;
this.visible = false; this.visible = false;
} else { } else {
let optionIndex = -1; let optionIndex = -1;
this.selected.forEach((item, index) => { this.selected.forEach((item, index) => {
if (item === option || item.label === option.label) { if (item === option || item.currentLabel === option.currentLabel) {
optionIndex = index; optionIndex = index;
} }
}); });