vue事件

秒速五厘米 2021-12-20 01:15 329阅读 0赞
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style type="text/css">
  7. .div1{
  8. width: 300px;
  9. height: 300px;
  10. margin: 0 auto;
  11. background: skyblue;
  12. }
  13. </style>
  14. <script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
  15. </head>
  16. <body>
  17. <div id="app">
  18. <div class="div1" :style="{ background:color }" @click = 'changeColor($event,1)'>
  19. </div>
  20. <ul>
  21. <li v-for='(item,index) in list' @click='getIndex($event,index)' :data-index='index' >{
  22. {item}}</li>
  23. </ul>
  24. </div>
  25. <script type="text/javascript">
  26. var app = new Vue({
  27. el:'#app',
  28. data:{
  29. color:'skyblue',
  30. list:[1,2,3,4]
  31. },
  32. methods:{
  33. changeColor:function(e,index){
  34. console.log(e)
  35. console.log(index)
  36. this.color = 'pink'
  37. },
  38. getIndex(e,index){
  39. console.log(e)
  40. console.log(index)
  41. console.log(e.target.dataset.index)//这种事件传值的方式,可以适用任何地方
  42. }
  43. }
  44. })
  45. </script>
  46. </body>
  47. </html>

转载于:https://www.cnblogs.com/wwthuanyu/p/10554842.html

发表评论

表情:
评论列表 (有 0 条评论,329人围观)

还没有评论,来说两句吧...

相关阅读

    相关 vue事件

    声明: 本文主要是照着官网教学自己敲了一遍,纯属动手练习,没什么技术含量。 -------------------- 事件: 事件监听(事件绑定):使用v-on:监

    相关 vue @scroll 事件

    vue 的 scroll 事件 做首页按需加载的时候  滚动条滚动到底部之后加载 由于如果绑定在window上,那么路由切换之后,事件依然会被触发,所以在div元素上绑定