1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <template> <div id="app2"> <p v-for="item in items" :key="item.id">{{item.message}}</p> <button class="btn" @click="handClick()">更改数据</button> </div> </template>
<script> export default { data() { return { items: [ { message: "one", id: "1" }, { message: "two", id: "2" }, { message: "three", id: "3" } ] }; }, mounted(){ this.items[0]={message:"测试",id:"4"}; this.$set(this.items,0,{message:"测试",id:"4"}); console.log(this.items) }, methods: {
handClick() {
this.$set(this.items, 0, { message: "更改one的值", id: "0" }); }, } }; </script>
<style> </style>
|