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

69 lines
1.4 KiB
Vue
Raw Normal View History

2018-02-22 04:07:37 +00:00
<script>
2019-01-12 03:33:27 +00:00
import Select, { Option } from '../index';
import '../assets/index.less';
import { fetch } from './tbFetchSuggest';
2018-02-22 04:07:37 +00:00
export default {
2019-09-28 12:45:07 +00:00
data() {
2018-02-22 04:07:37 +00:00
return {
data: [],
value: [],
2019-01-12 03:33:27 +00:00
};
2018-02-22 04:07:37 +00:00
},
methods: {
2019-09-28 12:45:07 +00:00
onKeyDown(e) {
2018-02-22 04:07:37 +00:00
if (e.keyCode === 13) {
2019-01-12 03:33:27 +00:00
console.log('onEnter', this.value);
this.jump(this.value);
2018-02-22 04:07:37 +00:00
}
},
2019-09-28 12:45:07 +00:00
onSelect(value) {
2019-01-12 03:33:27 +00:00
console.log('select ', value);
this.jump(value);
2018-02-22 04:07:37 +00:00
},
2019-09-28 12:45:07 +00:00
jump(v) {
2019-01-12 03:33:27 +00:00
console.log('jump ', v);
2019-09-28 12:45:07 +00:00
// location.href = 'https://s.taobao.com/search?q=' + encodeURIComponent(v);
2018-02-22 04:07:37 +00:00
},
2019-09-28 12:45:07 +00:00
fetchData(value) {
2019-01-12 03:33:27 +00:00
this.value = 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-22 04:07:37 +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 => {
2019-01-12 03:33:27 +00:00
return <Option key={d.value}>{d.text}</Option>;
});
2019-09-28 12:45:07 +00:00
return (
<div>
<h2>suggest</h2>
2018-02-22 04:07:37 +00:00
2019-09-28 12:45:07 +00:00
<div onKeydown={this.onKeyDown}>
<Select
style={{ width: '500px' }}
combobox
value={this.value}
placeholder="placeholder"
defaultActiveFirstOption={false}
getInputElement={() => <input />}
showArrow={false}
notFoundContent=""
onChange={this.fetchData}
onSelect={this.onSelect}
filterOption={false}
>
{options}
</Select>
</div>
2018-02-22 04:07:37 +00:00
</div>
2019-09-28 12:45:07 +00:00
);
2018-02-22 04:07:37 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-02-22 04:07:37 +00:00
</script>