Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue antd

作者:一杯酒悲痛人   发布日期:2025-03-11   浏览:273

// 示例代码:使用 Vue 和 Ant Design 实现一个简单的表单

<template>
  <a-form :form="form" @submit="handleSubmit">
    <a-form-item label="用户名">
      <a-input v-decorator="['username', { rules: [{ required: true, message: '请输入用户名!' }] }]" />
    </a-form-item>
    <a-form-item label="密码">
      <a-input-password v-decorator="['password', { rules: [{ required: true, message: '请输入密码!' }] }]" />
    </a-form-item>
    <a-form-item>
      <a-button type="primary" html-type="submit">
        提交
      </a-button>
    </a-form-item>
  </a-form>
</template>

<script>
export default {
  data() {
    return {
      form: this.$form.createForm(this, { name: 'login_form' }),
    };
  },
  methods: {
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('Received values of form: ', values);
        }
      });
    },
  },
};
</script>

<style scoped>
/* 可以在这里添加一些样式 */
</style>

解释说明:

  1. 模板部分 (<template>):

    • 使用了 a-forma-form-item 组件来创建一个表单。
    • a-inputa-input-password 分别用于输入用户名和密码。
    • v-decorator 指令用于绑定表单项的验证规则,确保用户输入符合要求。
  2. 脚本部分 (<script>):

    • data 函数中初始化了一个表单实例 form
    • handleSubmit 方法在表单提交时被调用,它会验证表单字段并输出有效数据。
  3. 样式部分 (<style scoped>):

    • 可以在这里为组件添加特定的样式,scoped 属性确保样式仅应用于当前组件。

上一篇:vue3 调用子组件方法

下一篇:vue eventbus

大家都在看

vue.config.js configu

node.js vue

vue查看版本

vue等待几秒

vue3 setup computed

vue screenfull

vue json.stringify

vue 遍历list

typescript vue

vue 复选框

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站