表单修饰符.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  8. <link href="../css/style.css" rel="stylesheet"> </head>
  9. <body>
  10. <div id="myApp">
  11. <h1>用户注册</h1>
  12. <div>
  13. <label for="username">用户:</label>
  14. <input type="text" id="username" v-model.lazy="username" @change="checkUsername">
  15. <span v-if="checkUsernameOK">可注册</span>
  16. </div>
  17. <div>
  18. <label for="age">年龄:</label>
  19. <input type="number" id="age" v-model.number="age">
  20. </div>
  21. <div>
  22. <label for="content">个人简介:</label><br/>
  23. <textarea id="content" v-model.trim="content" cols="55" rows="8"></textarea>
  24. </div>
  25. <h4>信息区</h4>
  26. <p>{{username}}</p>
  27. <p>{{age}}</p>
  28. <p><pre>{{content}}</pre></p>
  29. </div>
  30. <script>
  31. var myApp = new Vue({
  32. el: '#myApp',
  33. data: {
  34. username: "",
  35. checkUsernameOK: false,
  36. age: "",
  37. content: "",
  38. },
  39. methods: {
  40. checkUsername: function(){
  41. if (this.username.length > 0) this.checkUsernameOK = true;
  42. else this.checkUsernameOK = false;
  43. },
  44. },
  45. });
  46. </script>
  47. </body>
  48. </html>