element-ui——添加数据

简介: 添加数据

<top-bar @submitAction="submitAction"></top-bar>
methods:{
    // 添加——转TopBar.vue页面
    submitAction(rowData){
      this.$api.addList({rowData}).then(res=>{
        this.tableData.unshift(res.data)
      })
    },
}

TopBar.vue页面

submitForm() {
        this.$refs.form.validate(valid => {
          if (valid) {
            this.$emit('submitAction', this.form)
            this.dialogFormVisible = false
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },

完整页面

<template>
  <div class="top-bar">
    <el-input
      placeholder="请输入内容,按回车键搜索..."
      clearable
      @clear="getListdata"
      @keydown.enter.native="handleSearch"
      v-model="inputValue"
    >
      <template slot="append" class="search-first">
        <el-button class="search" @click="handleSearch">搜索</el-button>
      </template>
    </el-input>
    <el-button type="primary" @click="dialogFormVisible = true"
      >添加商品</el-button
    >
    <!-- 弹出层 -->
    <el-dialog
      title="添加用户信息"
      :visible.sync="dialogFormVisible"
      append-to-body
      width="30%"
    >
      <el-form :model="form" ref="form" :rules="rules">
        <el-form-item label="姓名:" prop="name" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="地址:" prop="address" :label-width="formLabelWidth">
          <el-input v-model="form.address" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="爱好:" prop="likes" :label-width="formLabelWidth">
          <el-input v-model="form.likes" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      inputValue: "",
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name: "",
        address: "",
        likes: "",
      },
      formLabelWidth: "120px",
      rules: {
        name: { required: true, message: '请输入姓名', trigger: 'blur' },
        address: { required: true, message: '请输入地址', trigger: 'blur' },
        likes: { required: true, message: '请输入爱好', trigger: 'blur' }
      }
    };
  },
  methods: {
    // 传一个函数submitAction把this.form传给父组件
     submitForm() {
        this.$refs.form.validate(valid => {
          if (valid) {
            this.$emit('submitAction', this.form)
            this.dialogFormVisible = false
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    handleSearch() {
      this.$emit("handleSearch", this.inputValue);
    },
    getListdata() {
      this.$emit("getdataList");
    },
  },
};
</script>
<style lang="less" scoped>
.top-bar {
  margin-bottom: 5px;
  .el-input {
    width: 300px;
    .search-first {
      cursor: pointer;
      margin-right: 10px;
    }
    .search {
      color: #000;
    }
  }
  .el-button {
    height: 40px;
  }
}
/deep/.v-modal {
  z-index: -1 !important;
}
/deep/.el-input__inner {
  width: 300px;
}
</style>
相关文章
|
9月前
|
JavaScript
vue element-ui中有关表格中的数据整条显示红色/绿色等等颜色的问题
vue element-ui中有关表格中的数据整条显示红色/绿色等等颜色的问题
335 1
|
7月前
|
前端开发
Element UI 【实战】纯前端对表格数据进行增删改查(内含弹窗表单、数据校验、时间日期格式)
Element UI 【实战】纯前端对表格数据进行增删改查(内含弹窗表单、数据校验、时间日期格式)
269 6
|
6月前
|
前端开发 JavaScript UED
element-ui 表格数据究竟隐藏着怎样的神秘样式与格式化技巧?快来揭开谜底!
【8月更文挑战第22天】《element-ui 表格数据样式及格式化案例》展示了如何利用 element-ui 的表格组件实现美观且易读的数据展示。通过简单配置,可以自定义表格样式,如边框、背景色等,并通过 formatter 实现数据格式化,例如将成绩保留一位小数。此外,还能依据条件设置行样式,如成绩达优则高亮显示,从而增强用户体验和数据可读性。
100 1
|
7月前
Element UI【级联选择器】el-cascader 获取选中内容的 label 数据,鼠标悬浮显示超长内容
Element UI【级联选择器】el-cascader 获取选中内容的 label 数据,鼠标悬浮显示超长内容
872 3
|
7月前
Element UI 多选表格--判断勾选数据行的 Checkbox 时为选中还是取消选中
Element UI 多选表格--判断勾选数据行的 Checkbox 时为选中还是取消选中
112 1
|
7月前
Element UI 多选表格【翻页多选】简易版(不支持翻页多选数据反显)
Element UI 多选表格【翻页多选】简易版(不支持翻页多选数据反显)
168 0
|
7月前
软件研发核心问题之在需求拆解过程中,“数据与UI如何关联”的问题如何解决
软件研发核心问题之在需求拆解过程中,“数据与UI如何关联”的问题如何解决
|
7月前
Element UI 多选表格【翻页多选】全能版(含翻页多选数据反显、toggleRowSelection失效的原因解析和解决方案)
Element UI 多选表格【翻页多选】全能版(含翻页多选数据反显、toggleRowSelection失效的原因解析和解决方案)
505 0
|
7月前
Element UI 表格数据格式化
Element UI 表格数据格式化
118 0
|
8月前
|
关系型数据库 MySQL API
实时计算 Flink版操作报错合集之同步MySQL数据到另一个MySQL数据库,第一次同步后源表数据发生变化时目标表没有相应更新,且Web UI中看不到运行的任务,该怎么解决
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
218 0

热门文章

最新文章