GPT答: |
7i24.cn
|
1. 在Vue中定义一个data属性,用于存储选中的下拉框数据。
```
data() {
return {
selectedData: ''
}
}
```
2. 在下拉框组件中绑定v-model指令,将选中的数据绑定到selectedData属性上。
```
<select v-model="selectedData">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
```
3. 定义一个方法,在提交表单时将selectedData属性的值发送给后端服务器进行保存。
```
methods: {
submitForm() {
axios.post('/api/save-data', { data: this.selectedData })
.then(response => console.log(response))
.catch(error => console.error(error));
}
}
```
4. 在表单提交按钮上绑定submitForm方法,当用户点击按钮时会触发该方法并将选中的数据发送给后端服务器进行保存。
```
<button @click="submitForm()">Submit</button>
```
|