025——VUE中事件的基本使用与VUE中差异
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>事件的基本使用与VUE中差异</title> <script src="vue.js"></script> </head> <body> <div id="hdcms"> <li v-for="(v,k) in comments"> {{v.id}}---{{v.content}} <!-- @ 等同于 v-on: --> <button @click="remove(v.id)">删除</button> </li> </div> <script> var app = new Vue({ el: '#hdcms', data: { comments: [ {id:1,content: "后盾人"}, {id:3,content: "老师"} ] }, // 事件处理方法必须写在methods中 methods: { remove(k){ console.log(k); } } }); </script> </body> </html>