前端之vue开发:事件

[复制链接]
579|0
 楼主| keer_zu 发表于 2020-12-26 11:27 | 显示全部楼层 |阅读模式


  1. <template>
  2.   <div id="helloworld">
  3.     <h1>{{ msg }}</h1>
  4.     <h2>Essential Links</h2>
  5.     <button v-on:click="say('hi')">Say hi</button>
  6.     <button v-on:click="say('what')">Say what</button>
  7.     <button v-on:click="counter += 1">增加 1</button>
  8.     <p>这个按钮被点击了 {{ counter }} 次。</p>
  9.   </div>
  10. </template>

  11. <script>
  12. export default {
  13.   name: 'HelloWorld',
  14.   data () {
  15.     return {
  16.       msg: 'Welcome to Your Vue.js App',
  17.       counter: 0
  18.     }
  19.   },
  20.   methods: {
  21.     say: function (message) {
  22.       alert(message)
  23.     }
  24.   }
  25. }
  26. </script>

  27. <!-- Add "scoped" attribute to limit CSS to this component only -->
  28. <style scoped>
  29. h1, h2 {
  30.   font-weight: normal;
  31. }
  32. ul {
  33.   list-style-type: none;
  34.   padding: 0;
  35. }
  36. li {
  37.   display: inline-block;
  38.   margin: 0 10px;
  39. }
  40. a {
  41.   color: #42b983;
  42. }
  43. </style>



html版本:
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
  6. <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
  7. </head>
  8. <body>
  9. <div id="app">
  10.   <button v-on:click="say('hi')">Say hi</button>
  11.   <button v-on:click="say('what')">Say what</button>
  12. </div>

  13. <script>
  14. new Vue({
  15.   el: '#app',
  16.   methods: {
  17.     say: function (message) {
  18.       alert(message)
  19.     }
  20.   }
  21. })
  22. </script>
  23. </body>
  24. </html>


您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:qq群:49734243 Email:zukeqiang@gmail.com

1488

主题

12949

帖子

55

粉丝
快速回复 在线客服 返回列表 返回顶部