Vuetify——表单提交

这是一个使用Vue.js编写的表单组件,用于创建和编辑数据。组件包含姓名、昵称、类型、描述、是否必备和唯一性等字段,并使用了Vuetify库的组件如`v-form`、`v-text-field`、`v-select`和`v-checkbox`。当表单数据不完整时,会显示错误提示。提交按钮根据操作类型(创建或编辑)调用不同的处理方法。
摘要由CSDN通过智能技术生成

index.vue:

<v-form class="pa-4" ref="form">
   <v-alert
        v-if="verifyResult"
        outlined
        type="error"
        class="text-left body-2 mb-8"
      >
    请填写完整表单数据
    </v-alert>
    <v-row no-gutters dense style="border-bottom:none!important;">
      <v-col cols="3" class="mt-2">
        <v-subheader>
          <span class="red--text">*</span>
          姓名
        </v-subheader>
      </v-col>
      <v-col cols="9" v-if="displayType === 'CREATE'">
        <v-text-field v-model="name" rows="1"></v-text-field>
      </v-col>
      <v-col cols="9" v-else style="margin-top:8px;">
        {{ name }}
      </v-col>
    </v-row>
    <v-row no-gutters dense style="border-bottom:none!important;">
      <v-col cols="3" class="mt-2">
        <v-subheader>
          <span class="red--text">*</span>
          昵称
        </v-subheader>
      </v-col>
      <v-col cols="9">
        <v-text-field v-model="display_name" rows="1"></v-text-field>
      </v-col>
    </v-row>
    <v-row no-gutters dense style="border-bottom:none!important;">
      <v-col cols="3" class="mt-2">
        <v-subheader>
          <span class="red--text">*</span>
          类型
        </v-subheader>
      </v-col>
      <v-col class="d-flex" cols="12" sm="6">
        <v-select
          :items="types"
          :label="value_type ? '' : '请选择'"
          item-text="name"
          item-value="id"
          v-model="value_type"
          @change="getvalue_typeSelected(value_type)"
        ></v-select>
      </v-col>
    </v-row>
    <v-row no-gutters dense style="border-bottom:none!important;">
      <v-col cols="3" class="mt-2">
        <v-subheader>
          <span class="red--text">*</span>
          描述
        </v-subheader>
      </v-col>
      <v-col cols="9">
        <v-text-field v-model="description" rows="1"></v-text-field>
      </v-col>
    </v-row>
    <v-row no-gutters dense style="border-bottom:none!important;">
      <v-col cols="3" class="mt-2">
        <v-subheader>
          <span class="red--text">*</span>
          是否必备
        </v-subheader>
      </v-col>
      <v-col cols="9">
        <v-checkbox class="v-label" v-model="required"></v-checkbox>
      </v-col>
    </v-row>
    <v-row no-gutters dense style="border-bottom:none!important;">
      <v-col cols="3" class="mt-2">
        <v-subheader>
          <span class="red--text">*</span>
          唯一
        </v-subheader>
      </v-col>
      <v-col cols="9" v-if="!(displayType === 'EDIT')">
        <v-checkbox
          class="v-label"
          v-model="unique"
          :disabled="displayType === 'EDIT'"
        ></v-checkbox>
      </v-col>
      <v-col v-else cols="9" style="margin-top:8px;align-self: center;">
        {{ unique ? "是" : "否" }}
      </v-col>
    </v-row>
    <v-row
      no-gutters
      dense
      style="align-items:center;"
      v-if="displayType === 'EDIT'"
    >
      <v-col cols="3" class="mt-2">
        <v-subheader>
          <span class="red--text"></span>
          是否上进
        </v-subheader>
      </v-col>
      <v-col cols="9" style="margin-top:8px;">
        {{ virtual ? "是" : "否" }}
      </v-col>
    </v-row>
    <v-row>
      <v-col class="d-flex" cols="3"></v-col>
      <v-col cols="9" class="text-left">
        <v-btn elevation="4" medium color="primary" @click="submit">
          {{ displayType === "CREATE" ? "新建" : "修改" }}</v-btn
        >
        <v-btn
          class="ml-6"
          elevation="0"
          medium
          color="gary"
          @click="cancel"
          >取消</v-btn
        >
      </v-col>
    </v-row>
  </v-form>


<script>
export default{
	data(){
		displayType: "CREATE",
      editId: null,
      verifyResult: false,
      name: "",
      display_name: "",
      description: "",
      value_type: "",
      required: false,
      unique: false,
      builtin: false,
      virtual: false,
      types: [
        {
          id: "STRING",
          name: "字符串类型"
        },
        {
          id: "BOOLEAN",
          name: "布尔值"
        },
        {
          id: "INTEGER",
          name: "数字类型"
        },
        {
          id: "DATETIME",
          name: "日期时间类型"
        },
        {
          id: "DATE",
          name: "日期类型"
        }
      ]
	},
	methods:{
		getvalue_typeSelected(val) {
      		this.value_type = val;
	    },
	    submit() {
	      if (
	        this.name.trim() !== "" &&
	        this.display_name.trim() !== "" &&
	        this.value_type.trim() !== "" &&
	        this.description.trim() !== ""
	      ) {
	      	//调提交接口
	        this.displayType === "CREATE" ? this.toCreate() : this.toEdit();
	      } else {
	        this.verifyResult = true;
	        setTimeout(() => {
	          this.verifyResult = false;
	        }, 2000);
	      }
	    },
	}
}


</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值