v-model绑定 select 的代码实例
<body> <div id="app"> <!-- select的单选 --> <select v-model="fruit"> <option value="apple">苹果</option> <option value="orange">橘子</option> <option value="banana">香蕉</option> </select> <h2>单选: {{fruit}}</h2> <hr> <!-- select的多选 --> <select multiple size="3" v-model="fruits"> <option value="apple">苹果</option> <option value="orange">橘子</option> <option value="banana">香蕉</option> </select> <h2>多选: {{fruits}}</h2> </div> <script src="../lib/vue.js"></script> <script> // 1.创建app const app = Vue.createApp({ // data: option api data() { return { fruit: "orange", fruits: [] } }, }) // 2.挂载app app.mount("#app") </script> </body>
本文来自博客园,作者:杨建鑫,转载请注明原文链接:https://www.cnblogs.com/qd-lbxx/p/16595172.html