代码如下:
<a-button @click="">按钮</a-button>
<template v-if="nn">
<a-select>
<a-select-option value="a">a</a-select-option>
<a-select-option value="b">b</a-select-option>
</a-select>
</template>
<template v-else>
<a-select>
<a-select-option value="a1">a1</a-select-option>
<a-select-option value="b2">b2</a-select-option>
</a-select>
</template>
代码解释:
按钮可以控制下方两个select的显示与隐藏
问题:
第一个下拉框选择选项后,点击按钮,第二个下拉框呈现第一个下拉框选择的内容???
解决方案:
为select添加v-model
<a-button @click="">按钮</a-button>
<template v-if="nn">
<a-select v-model="data1">
<a-select-option value="a">a</a-select-option>
<a-select-option value="b">b</a-select-option>
</a-select>
</template>
<template v-else>
<a-select v-model="data2">
<a-select-option value="a1">a1</a-select-option>
<a-select-option value="b2">b2</a-select-option>
</a-select>
</template>
原因是什么呢????