作用:表单和数据同步(绑定)
    参考vue官网文档 https://cn.vuejs.org/v2/guide/forms.html

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>vue的双向数据绑定v-model</title>
    8. <style>
    9. </style>
    10. </head>
    11. <body>
    12. <div id='app'>
    13. <p>{{msg}}</p>
    14. <input type="text" v-model='msg'>
    15. <!-- 复选框单选 -->
    16. <label for="checkbox">{{checked}}</label>
    17. <input type="checkbox" id='checkbox' v-model='checked'>
    18. <div class="box">
    19. <label for="a">黄瓜</label>
    20. <input type="checkbox" id='a' value='黄瓜' v-model='checkedNames'>
    21. <label for="b">西红柿</label>
    22. <input type="checkbox" id='b' value='西红柿' v-model='checkedNames'>
    23. <label for="c">芸豆</label>
    24. <input type="checkbox" id='c' value='芸豆' v-model='checkedNames'>
    25. <br />
    26. <span>{{checkedNames}}</span>
    27. </div>
    28. <label>{{txt}}</label>
    29. <input v-model.lazy="txt">
    30. <label>{{msg2}}</label>
    31. <input v-model.trim="msg2">
    32. </div>
    33. <script src="./vue.js"></script>
    34. <script>
    35. new Vue({
    36. el: '#app',
    37. data: {
    38. msg: 'ecithy',
    39. msg2: '',
    40. txt: '',
    41. checked: false,
    42. checkedNames: []
    43. },
    44. methods: {
    45. },
    46. })
    47. </script>
    48. </body>
    49. </html>