Commit e99320431095b04b723424f92c0d89efd97810d7
1 parent
d6070b23
fixed #978
Showing
2 changed files
with
159 additions
and
158 deletions
Show diff stats
examples/routers/select.vue
| 1 | -<!--<template>--> | ||
| 2 | - <!--<Row>--> | ||
| 3 | - <!--<i-col span="4">{{model}}</i-col>--> | ||
| 4 | - <!--<i-col span="8">--> | ||
| 5 | - <!--<i-select v-model="model" :label="['L Alabama', 'L Hawaii']" multiple @input="handleInput" filterable remote :remote-method="remoteMethod" :loading="loading" clearable>--> | ||
| 6 | - <!--<i-option v-for="option in options" :value="option.value" :key="new Date()">{{option.label}}</i-option>--> | ||
| 7 | - <!--</i-select>--> | ||
| 8 | - <!--</i-col>--> | ||
| 9 | - <!--</Row>--> | ||
| 10 | -<!--</template>--> | ||
| 11 | - | ||
| 12 | -<!--<script>--> | ||
| 13 | - <!--export default {--> | ||
| 14 | - <!--data () {--> | ||
| 15 | - <!--return {--> | ||
| 16 | -<!--// model: 'Alabama',--> | ||
| 17 | - <!--model: ['Alabama', 'Hawaii'],--> | ||
| 18 | - <!--options: [--> | ||
| 19 | - | ||
| 20 | - <!--],--> | ||
| 21 | - <!--list: [],--> | ||
| 22 | - <!--loading: false,--> | ||
| 23 | - <!--states: ["Al", "Alabama", "Alaska", "Arizona",--> | ||
| 24 | - <!--"Arkansas", "California", "Colorado",--> | ||
| 25 | - <!--"Connecticut", "Delaware", "Florida",--> | ||
| 26 | - <!--"Georgia", "Hawaii", "Idaho", "Illinois",--> | ||
| 27 | - <!--"Indiana", "Iowa", "Kansas", "Kentucky",--> | ||
| 28 | - <!--"Louisiana", "Maine", "Maryland",--> | ||
| 29 | - <!--"Massachusetts", "Michigan", "Minnesota",--> | ||
| 30 | - <!--"Mississippi", "Missouri", "Montana",--> | ||
| 31 | - <!--"Nebraska", "Nevada", "New Hampshire",--> | ||
| 32 | - <!--"New Jersey", "New Mexico", "New York",--> | ||
| 33 | - <!--"North Carolina", "North Dakota", "Ohio",--> | ||
| 34 | - <!--"Oklahoma", "Oregon", "Pennsylvania",--> | ||
| 35 | - <!--"Rhode Island", "South Carolina",--> | ||
| 36 | - <!--"South Dakota", "Tennessee", "Texas",--> | ||
| 37 | - <!--"Utah", "Vermont", "Virginia",--> | ||
| 38 | - <!--"Washington", "West Virginia", "Wisconsin",--> | ||
| 39 | - <!--"Wyoming"]--> | ||
| 40 | - <!--}--> | ||
| 41 | - <!--},--> | ||
| 42 | - <!--mounted () {--> | ||
| 43 | - <!--this.options = [--> | ||
| 44 | -<!--// {--> | ||
| 45 | -<!--// label: '全部',--> | ||
| 46 | -<!--// value: 0--> | ||
| 47 | -<!--// },{--> | ||
| 48 | -<!--// label: '苹果',--> | ||
| 49 | -<!--// value: 1--> | ||
| 50 | -<!--// },{--> | ||
| 51 | -<!--// label: '香蕉',--> | ||
| 52 | -<!--// value: 2--> | ||
| 53 | -<!--// },{--> | ||
| 54 | -<!--// label: '西瓜',--> | ||
| 55 | -<!--// value: 3--> | ||
| 56 | -<!--// }--> | ||
| 57 | - <!--];--> | ||
| 58 | - <!--},--> | ||
| 59 | - <!--methods: {--> | ||
| 60 | - <!--handleAdd () {--> | ||
| 61 | - <!--this.options = [--> | ||
| 62 | - <!--{--> | ||
| 63 | - <!--label: '全部',--> | ||
| 64 | - <!--value: 0--> | ||
| 65 | - <!--},{--> | ||
| 66 | - <!--label: '苹果',--> | ||
| 67 | - <!--value: 1--> | ||
| 68 | - <!--},{--> | ||
| 69 | - <!--label: '香蕉',--> | ||
| 70 | - <!--value: 2--> | ||
| 71 | - <!--},{--> | ||
| 72 | - <!--label: '西瓜',--> | ||
| 73 | - <!--value: 3--> | ||
| 74 | - <!--}--> | ||
| 75 | - <!--]--> | ||
| 76 | - <!--},--> | ||
| 77 | - <!--remoteMethod (query) {--> | ||
| 78 | - <!--console.log(13)--> | ||
| 79 | - <!--if (query !== '') {--> | ||
| 80 | - <!--this.loading = true;--> | ||
| 81 | - <!--setTimeout(() => {--> | ||
| 82 | - <!--this.loading = false;--> | ||
| 83 | - <!--this.options = this.list.filter(item => {--> | ||
| 84 | - <!--return item.label.toLowerCase()--> | ||
| 85 | - <!--.indexOf(query.toLowerCase()) > -1;--> | ||
| 86 | - <!--});--> | ||
| 87 | - <!--}, 500);--> | ||
| 88 | - <!--} else {--> | ||
| 89 | - <!--this.options = [];--> | ||
| 90 | - <!--}--> | ||
| 91 | - <!--},--> | ||
| 92 | - <!--handleInput () {--> | ||
| 93 | -<!--// console.log(1)--> | ||
| 94 | - <!--}--> | ||
| 95 | - <!--},--> | ||
| 96 | - <!--mounted () {--> | ||
| 97 | - <!--this.list = this.states.map(item => {--> | ||
| 98 | - <!--return {--> | ||
| 99 | - <!--value: item,--> | ||
| 100 | - <!--label: 'L ' + item--> | ||
| 101 | - <!--};--> | ||
| 102 | - <!--});--> | ||
| 103 | - <!--}--> | ||
| 104 | - <!--}--> | ||
| 105 | -<!--</script>--> | ||
| 106 | - | ||
| 107 | - | ||
| 108 | <template> | 1 | <template> |
| 109 | - <div> | ||
| 110 | - <Row style="width: 400px;"> | ||
| 111 | - <i-col span="12" style="padding-right:10px"> | ||
| 112 | - <Select v-model="model11" filterable> | ||
| 113 | - <Option v-for="item in cityList" :value="item.value" :key="item">{{ item.label }}</Option> | ||
| 114 | - </Select> | ||
| 115 | - </i-col> | ||
| 116 | - <i-col span="12"> | ||
| 117 | - <Select v-model="model12" filterable multiple> | ||
| 118 | - <Option v-for="item in cityList" :value="item.value" :key="item">{{ item.label }}</Option> | ||
| 119 | - </Select> | ||
| 120 | - </i-col> | ||
| 121 | - </Row> | ||
| 122 | - <Button @click="handleSet">set</Button> | ||
| 123 | - </div> | 2 | + <Row> |
| 3 | + <i-col span="4">{{model}}</i-col> | ||
| 4 | + <i-col span="8"> | ||
| 5 | + <i-select v-model="model" multiple @input="handleInput" filterable remote :remote-method="remoteMethod" :loading="loading" clearable> | ||
| 6 | + <i-option v-for="option in options" :value="option.value" :key="new Date()">{{option.label}}</i-option> | ||
| 7 | + </i-select> | ||
| 8 | + </i-col> | ||
| 9 | + </Row> | ||
| 124 | </template> | 10 | </template> |
| 11 | + | ||
| 125 | <script> | 12 | <script> |
| 126 | export default { | 13 | export default { |
| 127 | data () { | 14 | data () { |
| 128 | return { | 15 | return { |
| 129 | - cityList: [ | ||
| 130 | - { | ||
| 131 | - value: 'beijing', | ||
| 132 | - label: '北京市' | ||
| 133 | - }, | ||
| 134 | - { | ||
| 135 | - value: 'shanghai', | ||
| 136 | - label: '上海市' | ||
| 137 | - }, | ||
| 138 | - { | ||
| 139 | - value: 'shenzhen', | ||
| 140 | - label: '深圳市' | ||
| 141 | - }, | ||
| 142 | - { | ||
| 143 | - value: 'hangzhou', | ||
| 144 | - label: '杭州市' | ||
| 145 | - }, | ||
| 146 | - { | ||
| 147 | - value: 'nanjing', | ||
| 148 | - label: '南京市' | ||
| 149 | - }, | ||
| 150 | - { | ||
| 151 | - value: 'chongqing', | ||
| 152 | - label: '重庆市' | ||
| 153 | - } | 16 | +// model: 'Alabama', |
| 17 | + model: ['Alabama', 'Hawaii'], | ||
| 18 | + options: [ | ||
| 19 | + | ||
| 154 | ], | 20 | ], |
| 155 | - model11: '', | ||
| 156 | - model12: [] | 21 | + list: [], |
| 22 | + loading: false, | ||
| 23 | + states: ["Al", "Alabama", "Alaska", "Arizona", | ||
| 24 | + "Arkansas", "California", "Colorado", | ||
| 25 | + "Connecticut", "Delaware", "Florida", | ||
| 26 | + "Georgia", "Hawaii", "Idaho", "Illinois", | ||
| 27 | + "Indiana", "Iowa", "Kansas", "Kentucky", | ||
| 28 | + "Louisiana", "Maine", "Maryland", | ||
| 29 | + "Massachusetts", "Michigan", "Minnesota", | ||
| 30 | + "Mississippi", "Missouri", "Montana", | ||
| 31 | + "Nebraska", "Nevada", "New Hampshire", | ||
| 32 | + "New Jersey", "New Mexico", "New York", | ||
| 33 | + "North Carolina", "North Dakota", "Ohio", | ||
| 34 | + "Oklahoma", "Oregon", "Pennsylvania", | ||
| 35 | + "Rhode Island", "South Carolina", | ||
| 36 | + "South Dakota", "Tennessee", "Texas", | ||
| 37 | + "Utah", "Vermont", "Virginia", | ||
| 38 | + "Washington", "West Virginia", "Wisconsin", | ||
| 39 | + "Wyoming"] | ||
| 157 | } | 40 | } |
| 158 | }, | 41 | }, |
| 42 | + mounted () { | ||
| 43 | + this.options = [ | ||
| 44 | +// { | ||
| 45 | +// label: '全部', | ||
| 46 | +// value: 0 | ||
| 47 | +// },{ | ||
| 48 | +// label: '苹果', | ||
| 49 | +// value: 1 | ||
| 50 | +// },{ | ||
| 51 | +// label: '香蕉', | ||
| 52 | +// value: 2 | ||
| 53 | +// },{ | ||
| 54 | +// label: '西瓜', | ||
| 55 | +// value: 3 | ||
| 56 | +// } | ||
| 57 | + ]; | ||
| 58 | + }, | ||
| 159 | methods: { | 59 | methods: { |
| 160 | - handleSet () { | ||
| 161 | - this.model11 = 'shanghai'; | ||
| 162 | -// this.model12 = ['beijing']; | 60 | + handleAdd () { |
| 61 | + this.options = [ | ||
| 62 | + { | ||
| 63 | + label: '全部', | ||
| 64 | + value: 0 | ||
| 65 | + },{ | ||
| 66 | + label: '苹果', | ||
| 67 | + value: 1 | ||
| 68 | + },{ | ||
| 69 | + label: '香蕉', | ||
| 70 | + value: 2 | ||
| 71 | + },{ | ||
| 72 | + label: '西瓜', | ||
| 73 | + value: 3 | ||
| 74 | + } | ||
| 75 | + ] | ||
| 76 | + }, | ||
| 77 | + remoteMethod (query) { | ||
| 78 | + console.log(13) | ||
| 79 | + if (query !== '') { | ||
| 80 | + this.loading = true; | ||
| 81 | + setTimeout(() => { | ||
| 82 | + this.loading = false; | ||
| 83 | + this.options = this.list.filter(item => { | ||
| 84 | + return item.label.toLowerCase() | ||
| 85 | + .indexOf(query.toLowerCase()) > -1; | ||
| 86 | + }); | ||
| 87 | + }, 500); | ||
| 88 | + } else { | ||
| 89 | + this.options = []; | ||
| 90 | + } | ||
| 91 | + }, | ||
| 92 | + handleInput () { | ||
| 93 | +// console.log(1) | ||
| 163 | } | 94 | } |
| 95 | + }, | ||
| 96 | + mounted () { | ||
| 97 | + this.list = this.states.map(item => { | ||
| 98 | + return { | ||
| 99 | + value: item, | ||
| 100 | + label: 'L ' + item | ||
| 101 | + }; | ||
| 102 | + }); | ||
| 164 | } | 103 | } |
| 165 | } | 104 | } |
| 166 | </script> | 105 | </script> |
| 106 | + | ||
| 107 | + | ||
| 108 | +<!--<template>--> | ||
| 109 | + <!--<div>--> | ||
| 110 | + <!--<Row style="width: 400px;">--> | ||
| 111 | + <!--<i-col span="12" style="padding-right:10px">--> | ||
| 112 | + <!--<Select v-model="model11" filterable>--> | ||
| 113 | + <!--<Option v-for="item in cityList" :value="item.value" :key="item">{{ item.label }}</Option>--> | ||
| 114 | + <!--</Select>--> | ||
| 115 | + <!--</i-col>--> | ||
| 116 | + <!--<i-col span="12">--> | ||
| 117 | + <!--<Select v-model="model12" filterable multiple>--> | ||
| 118 | + <!--<Option v-for="item in cityList" :value="item.value" :key="item">{{ item.label }}</Option>--> | ||
| 119 | + <!--</Select>--> | ||
| 120 | + <!--</i-col>--> | ||
| 121 | + <!--</Row>--> | ||
| 122 | + <!--<Button @click="handleSet">set</Button>--> | ||
| 123 | + <!--</div>--> | ||
| 124 | +<!--</template>--> | ||
| 125 | +<!--<script>--> | ||
| 126 | + <!--export default {--> | ||
| 127 | + <!--data () {--> | ||
| 128 | + <!--return {--> | ||
| 129 | + <!--cityList: [--> | ||
| 130 | + <!--{--> | ||
| 131 | + <!--value: 'beijing',--> | ||
| 132 | + <!--label: '北京市'--> | ||
| 133 | + <!--},--> | ||
| 134 | + <!--{--> | ||
| 135 | + <!--value: 'shanghai',--> | ||
| 136 | + <!--label: '上海市'--> | ||
| 137 | + <!--},--> | ||
| 138 | + <!--{--> | ||
| 139 | + <!--value: 'shenzhen',--> | ||
| 140 | + <!--label: '深圳市'--> | ||
| 141 | + <!--},--> | ||
| 142 | + <!--{--> | ||
| 143 | + <!--value: 'hangzhou',--> | ||
| 144 | + <!--label: '杭州市'--> | ||
| 145 | + <!--},--> | ||
| 146 | + <!--{--> | ||
| 147 | + <!--value: 'nanjing',--> | ||
| 148 | + <!--label: '南京市'--> | ||
| 149 | + <!--},--> | ||
| 150 | + <!--{--> | ||
| 151 | + <!--value: 'chongqing',--> | ||
| 152 | + <!--label: '重庆市'--> | ||
| 153 | + <!--}--> | ||
| 154 | + <!--],--> | ||
| 155 | + <!--model11: '',--> | ||
| 156 | + <!--model12: []--> | ||
| 157 | + <!--}--> | ||
| 158 | + <!--},--> | ||
| 159 | + <!--methods: {--> | ||
| 160 | + <!--handleSet () {--> | ||
| 161 | + <!--this.model11 = 'shanghai';--> | ||
| 162 | +<!--// this.model12 = ['beijing'];--> | ||
| 163 | + <!--}--> | ||
| 164 | + <!--}--> | ||
| 165 | + <!--}--> | ||
| 166 | +<!--</script>--> |
src/components/select/select.vue
| @@ -127,7 +127,8 @@ | @@ -127,7 +127,8 @@ | ||
| 127 | inputLength: 20, | 127 | inputLength: 20, |
| 128 | notFound: false, | 128 | notFound: false, |
| 129 | slotChangeDuration: false, // if slot change duration and in multiple, set true and after slot change, set false | 129 | slotChangeDuration: false, // if slot change duration and in multiple, set true and after slot change, set false |
| 130 | - model: this.value | 130 | + model: this.value, |
| 131 | + currentLabel: this.label | ||
| 131 | }; | 132 | }; |
| 132 | }, | 133 | }, |
| 133 | computed: { | 134 | computed: { |
| @@ -593,15 +594,15 @@ | @@ -593,15 +594,15 @@ | ||
| 593 | if (this.remote) { | 594 | if (this.remote) { |
| 594 | if (!this.multiple && this.model !== '') { | 595 | if (!this.multiple && this.model !== '') { |
| 595 | this.selectToChangeQuery = true; | 596 | this.selectToChangeQuery = true; |
| 596 | - if (this.label === '') this.label = this.model; | ||
| 597 | - this.lastQuery = this.label; | ||
| 598 | - this.query = this.label; | 597 | + if (this.currentLabel === '') this.currentLabel = this.model; |
| 598 | + this.lastQuery = this.currentLabel; | ||
| 599 | + this.query = this.currentLabel; | ||
| 599 | } else if (this.multiple && this.model.length) { | 600 | } else if (this.multiple && this.model.length) { |
| 600 | - if (this.label.length !== this.model.length) this.label = this.model; | 601 | + if (this.currentLabel.length !== this.model.length) this.currentLabel = this.model; |
| 601 | this.selectedMultiple = this.model.map((item, index) => { | 602 | this.selectedMultiple = this.model.map((item, index) => { |
| 602 | return { | 603 | return { |
| 603 | value: item, | 604 | value: item, |
| 604 | - label: this.label[index] | 605 | + label: this.currentLabel[index] |
| 605 | }; | 606 | }; |
| 606 | }); | 607 | }); |
| 607 | } | 608 | } |