前端学习-vue学习003-事件监听

教程链接

使用 v-on 指令监听 DOM 事件

<button v-on:click="increment">{{ count }}</button>

简写语法

<button @click="increment">{{ count }}</button>
<script setup>
import { ref } from 'vue'

const count = ref(0)
function increment() {
  count.value += 1
}
</script>

<template>
  <!-- 使此按钮生效 -->
  <button @click = "increment">count is: {{ count }}</button>
</template>
posted @ 2024-02-29 10:52  ayubene  阅读(18)  评论(0)    收藏  举报