Autocomplete 在v-for中使用自动完成
我对vuejs2非常陌生,但我正在尝试使用它 Im使用v-autocomplete组件,我从这里下载: 组件在循环v-for中,我无法正确设置道具所有道具都反映在所有组件上,正确的方法是什么 下面是一个需要理解的图像: 我的代码:Autocomplete 在v-for中使用自动完成,autocomplete,vuejs2,v-for,Autocomplete,Vuejs2,V For,我对vuejs2非常陌生,但我正在尝试使用它 Im使用v-autocomplete组件,我从这里下载: 组件在循环v-for中,我无法正确设置道具所有道具都反映在所有组件上,正确的方法是什么 下面是一个需要理解的图像: 我的代码: <template v-for="lote in remate.lotes"> <v-autocomplete :items="items" :ref="'search'" :v-model="lo
<template v-for="lote in remate.lotes">
<v-autocomplete
:items="items"
:ref="'search'"
:v-model="loteClienteForm.cliente"
:get-label="getLabel"
:keep-open="true"
input-class="form-control"
:component-item='UserAutocompleteTemplate'
@update-items="updatedItems">
</v-autocomplete>
</template>
我的vue页面:
<script>
import axios from 'axios'
import Autocomplete from 'v-autocomplete'
import UserAutocompleteTemplate from '../components/template/UserAutocompleteTemplate'
export default {
middleware: 'auth',
scrollToTop: false,
components: {
'v-autocomplete': Autocomplete
},
data: () => ({
items: [],
item: {},
loteClienteForm: new Form({}),
UserAutocompleteTemplate: UserAutocompleteTemplate
}),
methods: {
getLabel (item) {
if(item !== null){
return item.nombre
}
},
updatedItems (text) {
this.searchRemateClientes(text).then( (response) => {
this.items = response;
})
},
async searchRemateClientes(search){
const { data } = await axios.get('/api/search/remate-clientes', {params: {query: search}});
return data;
}
}
}
从“axios”导入axios
从“v-Autocomplete”导入自动完成
从“../components/template/UserAutocompleteTemplate”导入UserAutocompleteTemplate
导出默认值{
中间件:“auth”,
错误,
组成部分:{
“v-自动完成”:自动完成
},
数据:()=>({
项目:[],
项目:{},
LotusClientForm:新表单({}),
UserAutocompleteTemplate:UserAutocompleteTemplate
}),
方法:{
getLabel(项目){
如果(项!==null){
return item.nombre
}
},
updateItems(文本){
this.searchremateclients(文本)。然后((响应)=>{
此项=响应;
})
},
异步searchRemateClientes(搜索){
const{data}=wait axios.get('/api/search/remate clientes',{params:{query:search});
返回数据;
}
}
}
您示例中的
v-model
是loteclientform.cliente
,它不依赖v-for
forlote
,因此所有v-autocomplete
组件都使用与其模型相同的值
请注意,您的
v-autocomplete
组件中也缺少attribute属性。谢谢,我将loteclientform放在组件中修复了它!现在真是太棒了!