一个简单但可配置的Vue.js和Bootstrap 4自动完成和预输入组件。易于与任何基于JSON的API集成。
v2.3.0(06/18/2020)
# Yarn
$ yarn add vue-typeahead-bootstrap
# NPM
$ npm install vue-typeahead-bootstrap --save
1.安装并导入vue-typeahead-bootstrap组件。
import VueTypeaheadBootstrap from 'vue-typeahead-bootstrap';
2.注册组件。
// 全局
Vue.component('vue-typeahead-bootstrap', VueTypeaheadBootstrap)
// 或本地
export default {
components: {
VueTypeaheadBootstrap
}
}
3.使用预输入功能创建一个简单的国家/地区选择。
template>
<div>
Options: `Canada, United States, Mexico`,
<vue-typehead-bootstrap
:data="['Canada', 'United States', 'Mexico']"
v-model="query"
placeholder="Choose a country"
/>
Selected Country: {{query}}
</div>
</template>
export default {
data(){
return {
query: ''
}
}
}
4.可用 props 。
size: {
type: String,
default: null,
validator: size => ['lg', 'sm'].indexOf(size) > -1
},
value: {
type: String
},
disabled: {
type: Boolean,
default: false
},
data: {
type: Array,
required: true,
validator: d => d instanceof Array
},
serializer: {
type: Function,
default: (d) => d,
validator: d => d instanceof Function
},
backgroundVariant: String,
textVariant: String,
inputClass: {
type: String,
default: ''
},
maxMatches: {
type: Number,
default: 10
},
minMatchingChars: {
type: Number,
default: 2
},
disableSort: {
type: Boolean,
default: false
},
showOnFocus: {
type: Boolean,
default: false
},
showAllResults: {
type: Boolean,
default: false
},
autoClose: {
type: Boolean,
default: true
},
placeholder: String,
prepend: String,
append: String,
highlightClass: String