6_set.html 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. </div>
  19. <script src="vue.js"></script>
  20. <script>
  21. new Vue({
  22. el: '#app',
  23. data:{
  24. arr:['a','b','c','d'],
  25. person:{
  26. name:'zs'
  27. }
  28. },
  29. methods:{
  30. change(){
  31. console.log(111)
  32. // this.arr[0] = 'x'
  33. /* Vue中 不能使用数组[索引]修改数组 因为页面不更新 */
  34. /* Vue 要大写 */
  35. /* Vue.set(data数据,修改值的索引,修改的参数) */
  36. Vue.set(this.person,'name','lisi')
  37. }
  38. }
  39. })
  40. </script>
  41. </body>
  42. </html>