1.在<option>中缺省value属性,则提交数据时提交的是选定的文本。
切记易错点: 1,option中不要写value
2,switch的判断条件是this.operation。不需要写为this.operation.text
<div id='app'><select name="" id="" v-model:value="operation"><option>+</option><option>-</option><option>*</option><option>/</option></select></div>var vm = new Vue({el: '#app',data: {operation: ''},methods: {calculate() {switch (this.operation) {case '+':console.log(this.operation);break;case '-':console.log(this.operation);break;case '*':console.log(this.operation);break;case '/':console.log(this.operation);break;default:break;}}}})
2.可以在<option>中设定value属性,如此再向服务器提交的时候直接提交设定的value。
<div id='app'><select name="" id="" v-model:value="operation"><option value="+">+</option><option value="-">-</option><option value="*">*</option><option value="/">/</option></select></div>var vm = new Vue({el: '#app',data: {operation: ''},methods: {calculate() {switch (this.operation) {case '+':console.log(this.operation);break;case '-':console.log(this.operation);break;case '*':console.log(this.operation);break;case '/':console.log(this.operation);break;default:break;}}}})