Quasar框架q-select在v-model中设置一个对象比id
Quasar framework q-select sets an object in the v-model than the id
我的select
有以下代码
<q-select label="Select country"
behavior="menu"
:lazy-rules="true"
:rules="[val => !!val || 'Select your country']"
dense outlined v-model="form.code" :options="countries"
option-label="name" option-value="code">
</q-select>
还有我的 vuejs 代码
<script>
export default{
data:()=>({
form:{
code:""
}
countries:[
{name:"Country-1", code:"+101"},
{name:"Country-2", code:"+201"},
]
})
}
<script>
从上面我希望 form.code
的值是代码,例如:+101 但是当我检查时我发现该值是完整的对象。我错过了什么,因为在我的 select 上我已经设置了选项标签和选项值
我错过了什么?
您需要使用emit-value
和map-options
,参见:https://quasar.dev/vue-components/select#affecting-model
我的select
有以下代码 <q-select label="Select country"
behavior="menu"
:lazy-rules="true"
:rules="[val => !!val || 'Select your country']"
dense outlined v-model="form.code" :options="countries"
option-label="name" option-value="code">
</q-select>
还有我的 vuejs 代码
<script>
export default{
data:()=>({
form:{
code:""
}
countries:[
{name:"Country-1", code:"+101"},
{name:"Country-2", code:"+201"},
]
})
}
<script>
从上面我希望 form.code
的值是代码,例如:+101 但是当我检查时我发现该值是完整的对象。我错过了什么,因为在我的 select 上我已经设置了选项标签和选项值
我错过了什么?
您需要使用emit-value
和map-options
,参见:https://quasar.dev/vue-components/select#affecting-model