12_set.html 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <button @click="change()">修改</button>
  12. <ul>
  13. <li v-for="(val,index) in arr">
  14. {{val}}
  15. {{index}}
  16. </li>
  17. </ul>
  18. {{person.name}}
  19. </div>
  20. <script src="./vue.js"></script>
  21. <script>
  22. var app = new Vue({
  23. el: '#app',
  24. data:{
  25. arr: ['a','b','c','d','e'],
  26. person: {
  27. name: 'zs'
  28. }
  29. },
  30. methods:{
  31. change(){
  32. console.log(1111)
  33. // this.arr[0] = 'x'
  34. //在Vue中 不能使用数组[索引] 这样的方式修改数组
  35. //Vue.set(data数据,修改值的索引,修改的值)
  36. Vue.set(this.person,'name','lisi')
  37. }
  38. }
  39. })
  40. </script>
  41. </body>
  42. </html>