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

65 lines
1.3 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 {
data () {
return {
disabled: false,
data: [],
value: undefined,
2019-01-12 03:33:27 +00:00
};
2018-02-11 10:04:31 +00:00
},
methods: {
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
},
fetchData (value) {
if (value) {
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
}
},
toggleDisabled () {
2019-01-12 03:33:27 +00:00
this.disabled = !this.disabled;
2018-02-11 10:04:31 +00:00
},
},
render () {
2019-01-12 03:33:27 +00:00
const data = this.data;
2018-02-11 10:04:31 +00:00
const options = data.map((d) => {
2019-01-12 03:33:27 +00:00
return <Option key={d.value}><i>{d.text}</i></Option>;
});
2018-02-11 10:04:31 +00:00
return (<div>
<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>
2019-01-12 03:33:27 +00:00
</div>);
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>