【发布时间】:2021-06-27 04:33:47
【问题描述】:
有人可以帮助解决这个问题吗?我有一个动态选择下拉菜单。 “选择您的位置”的第一个默认选项默认情况下不可见。这是因为 v-model。我怎样才能让它工作? 我的父组件:
<template>
<div>
<Segments @select-segment-location-event="updateSegmentLocation" :segmentLocation="segmentLocation" />
</div>
</template>
我的子组件:
<template>
<div class="container">
<select v-model="segmentLocation" @change="selectSegmentLocation">
<option selected disabled>Choose your location...</option>
<option v-for="(segLoc, index) in segmentLocations"
:key="index"
:value="segLoc">{{ segLoc.name }}</option>
</select>
</div>
</template>
<script>
export default {
data() {
return {
segmentLocations: [
{ value: "Residential", name: 'Residential building' },
{ value: "Workplace", name: 'Workplace' },
{ value: "Hospitality", name: 'Hospitality or Retail' },
{ value: "Real Estate", name: 'Real Estate' },
{ value: "Commercial Parking", name: 'Commercial Parking' },
{ value: "Fleets", name: 'Fleets' },
{ value: "Cities & Governments", name: 'Cities & Governments' },
{ value: "Corridor", name: 'Highway, Corridor or Petrol Station' }
],
}
}
methods: {
selectSegmentLocation() {
this.$emit('select-segment-location-event', this.segmentLocation);
}
}
};
</script>
【问题讨论】:
-
您好,您可以在数据选项中添加
segementLocation,并使用默认值。喜欢segmentLocation: 'Choose your Location...'。
标签: vue.js