vue form sumit 防止提交 prevent 阻止表单提交

正常情况下 button是带sumit的属性的

<script setup lang="ts">
import {reactive} from "vue";

let form = reactive({
  name: "小曼",
  age: 123,
});
let submit = () => {
  console.log(form);
};
</script>

<template>
  <div>
    <form>
      <input type="text" v-model="form.name">
      <br>
      <input type="text" v-model="form.age">
      <br>
      <button @click="submit">提交</button>

    </form>
  </div>
</template>

页面提交会导致刷新 从而打印不出来可以添加prevent 阻止提交

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/128601173