<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>hello world</title> <script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script> </head> <body> <div id="app"> <!--text--> <input type="text" v-model="message"> <br> <br> <!--radio--> <label><input type="radio" value="male" v-model="gender">男</label> <label><input type="radio" value="female" v-model="gender">女</label> <br> <br> <!--checkbox--> <label><input type="checkbox" v-model="checked">已婚</label> <br> <!--多个勾选框--> <br> <label>属于第几类人员<input type="checkbox" value="1" v-model="multiChecked">1</label> <label><input type="checkbox" value="2" v-model="multiChecked">2</label> <label><input type="checkbox" value="3" v-model="multiChecked">3</label> <br> <!--select--> <br> <select v-model="selected"> <option selected>A</option> <option>B</option> <option>C</option> </select> <br> <br> <select v-model="multiSelected" multiple> <option selected>A</option> <option>B</option> <option>C</option> </select> <br> <br> <button v-on:click="reverseMessage">反转字符串</button> <p>-------------------<p> <span>R姓名:{{r_message}}</span> <p>姓名:{{message}}</p> <p>{{gender}}</p> <span>已婚:{{checked}}</span> <p>第[ {{multiChecked.join('')}} ]类人员</p> <span>选择你的目标成绩: {{selected}}</span> <br> <br> <span>实际成绩:{{multiSelected.join('|')}}</span> </div> <script> var vm = new Vue({ el: '#app', data: { message:'', gender:'', checked:'', multiChecked:[], selected:'', multiSelected:[], a:'checked', b:'checked', r_message:'', }, methods: { reverseMessage: function () { this.r_message = this.message.split('').reverse().join('') } } }); </script> </body>
参考 https://blog.csdn.net/moses_binson/article/details/88688621 的文章