Demo.vue 818 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <div class="demo1">
  3. <h2>姓名:{{ name }}</h2>
  4. <h2>年龄:{{ age }}</h2>
  5. <h2>性别:{{ sex }}</h2>
  6. <button @click="changeName">修改姓名</button>
  7. <button @click="changeAge">修改年龄</button>
  8. <button @click="changeSex">修改性别</button>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. name:"孙悟空",
  16. age:18,
  17. sex:"男"
  18. }
  19. },
  20. methods:{
  21. changeName() {
  22. this.name = '猪八戒'
  23. },
  24. changeAge() {
  25. this.age = 20
  26. },
  27. changeSex() {
  28. this.sex = '女'
  29. },
  30. }
  31. }
  32. </script>
  33. <style scoped>
  34. .demo1 {
  35. background: #00f;
  36. padding: 20px;
  37. }
  38. button {
  39. margin-left: 20px;
  40. }
  41. </style>