扩展vue(vuetify)组件的最佳方法是什么v-select.
例如,我想创建<v-city></v-city>一个扩展的组件,v-select其中props加载了最小的异步项,并选择了一个项.
我已经开始了 template
<template>
<v-select
:items="items"
v-model="item"
required
return-object
autocomplete
item-text="name"
item-value="id"
></v-select>
</template>
Run Code Online (Sandbox Code Playgroud)
和 script
<script>
export default {
name: 'v-city',
data()
{
return {
item: null,
items: [],
disabled: true
};
},
created()
{
this.$http({
method: 'GET',
url: '/api.cities'
})
.then(response => this.items = response.data)
.catch(console.warn);
},
methods: {},
watch: {
item(nv)
{
this.$emit('update', nv.id);
}
}
};
</script>
Run Code Online (Sandbox Code Playgroud)
用法:
<v-city @update="local.city = arguments[0]"></v-city>
我要归档的是:
<v-city v-model="local.city" label="Select city"></v-city>