ant-design-vue/components/vc-select/demo/force-suggest.vue

71 lines
1.4 KiB
Vue
Raw Normal View History

2018-02-11 10:04:31 +00:00
<script>
2019-01-12 03:33:27 +00:00
import Select, { Option } from '../index';
import { fetch } from './tbFetchSuggest';
import '../assets/index.less';
2018-02-11 10:04:31 +00:00
export default {
2019-09-28 12:45:07 +00:00
data() {
2018-02-11 10:04:31 +00:00
return {
disabled: false,
data: [],
value: undefined,
2019-01-12 03:33:27 +00:00
};
2018-02-11 10:04:31 +00:00
},
methods: {
2019-09-28 12:45:07 +00:00
onChange(value) {
2019-01-12 03:33:27 +00:00
console.log('select ', value);
2018-02-11 10:04:31 +00:00
// value.label = value.key
2019-01-12 03:33:27 +00:00
this.value = value;
2018-02-11 10:04:31 +00:00
},
2019-09-28 12:45:07 +00:00
fetchData(value) {
2018-02-11 10:04:31 +00:00
if (value) {
2019-09-28 12:45:07 +00:00
fetch(value, data => {
2019-01-12 03:33:27 +00:00
this.data = data;
});
2018-02-11 10:04:31 +00:00
} else {
2019-01-12 03:33:27 +00:00
this.data = [];
2018-02-11 10:04:31 +00:00
}
},
2019-09-28 12:45:07 +00:00
toggleDisabled() {
2019-01-12 03:33:27 +00:00
this.disabled = !this.disabled;
2018-02-11 10:04:31 +00:00
},
},
2019-09-28 12:45:07 +00:00
render() {
2019-01-12 03:33:27 +00:00
const data = this.data;
2019-09-28 12:45:07 +00:00
const options = data.map(d => {
return (
<Option key={d.value}>
<i>{d.text}</i>
</Option>
);
2019-01-12 03:33:27 +00:00
});
2019-09-28 12:45:07 +00:00
return (
2018-02-11 10:04:31 +00:00
<div>
2019-09-28 12:45:07 +00:00
<h2>force suggest</h2>
<p>
<button onClick={this.toggleDisabled}>toggle disabled</button>
</p>
<div>
<Select
labelInValue
onSearch={this.fetchData}
disabled={this.disabled}
value={this.value}
optionLabelProp="children"
placeholder="placeholder"
defaultActiveFirstOption
style={{ width: '500px' }}
onChange={this.onChange}
filterOption={false}
>
{options}
</Select>
</div>
2018-02-11 10:04:31 +00:00
</div>
2019-09-28 12:45:07 +00:00
);
2018-02-11 10:04:31 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-02-11 10:04:31 +00:00
</script>