vue v-on参数传递

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <p>{{ message }}</p>
      <button type="button" @click="onClickEvent">onClickEvent</button>
      <button type="button" @click="onClickAge(age)">onClickAge</button>
      <button type="button" @click="onClick(age, $event)">onClick</button>
    </div>

    <script>
      const app = new Vue({
        el: '#app',
        data: {
          message: 'Hello Vue.js!',
          age: 12,
        },
        methods: {
          onClickAge(age) {
            console.log('onClickAge ' + age);
          },
          onClickEvent(event) {
            console.log('onClickEvent ' + event);
          },
          onClick(age, event) {
            console.log('onClick ' + age);
            console.log('onClick ' + event);
          }
        },
      })
    </script>
  </body>
</html>

posted @ 2021-07-01 16:22  thomas_blog  阅读(218)  评论(0编辑  收藏  举报