VUE--ElementUI--后端界面--用戶管理(三)

一、用戶管理

  1. 界面
<template>
  <!-- 用戶管理 -->
  <div>
    <el-row class="topRow">
      <el-button type="primary" @click="addUser">添加用戶</el-button>
      <el-button type="success" @click="batchDel">批量刪除</el-button>
    </el-row>
    <el-table
      ref="multipleTable"
      :data="userData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <!-- 復(fù)選接鈕 -->
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="編號(hào)" prop="id" width="120"></el-table-column>
      <el-table-column prop="username" label="用戶" width="120"></el-table-column>
      <el-table-column prop="createTime" label="創(chuàng)建日期" show-overflow-tooltip></el-table-column>
      <el-table-column label="操作" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">編輯</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">刪除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :title="title" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="編號(hào)">
          <el-input v-model="form.id"></el-input>
        </el-form-item>
        <el-form-item label="用戶">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">確 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: { id: "", username: "", createTime: "" },
      userData: [
        { id: 1, username: "王小虎", createTime: "2019-08-13 15:00:00" },
        { id: 2, username: "李小七", createTime: "2019-08-13 15:00:00" },
        { id: 3, username: "張小八", createTime: "2019-08-13 15:00:00" }
      ],
      multipleSelection: [],
      title: "",
      dialogVisible: false
    };
  },
  methods: {
    // 選擇
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleClose() {
    this.dialogVisible = false;
   },
  }
};
</script>
<style scoped>
.topRow {
  margin-bottom: 10px;
  float: left;
}
</style>
  1. 刪除事件
    // 刪除
    handleDelete(index, rows) {
      this.userData.splice(index, 1);
    },
    batchDel() {
      this.multipleSelection.forEach(element => {
        this.userData.forEach((item, index) => {
          if (item.username == element.username) {
            this.userData.splice(index, 1);
          }
        });
      });
    },
  1. 添加編輯事件
    addUser() {
      this.form.id = "";
      this.form.username = "";
      this.title = "添加用戶";
      this.dialogVisible = true;
    },
    // 編輯
    handleEdit(index, rows) {
      this.title = "編輯用戶";
      this.dialogVisible = true;
      this.form.id = rows.id;
      this.form.username = rows.username;
      console.log(index + "->" + rows.username);
    },
  1. 保存事件
    save() {
      if (this.title == "添加用戶") {
         let user = { id: "", username: "", createTime: "" };
        user.id = this.form.id;
        user.username = this.form.username;
        user.createTime= "2019-08-14 10:00:00";
        this.userData.push(user);
        this.dialogVisible = false;
      } else if (this.title == "編輯用戶") {
         this.userData.forEach((item,index)=>{
           if(item.username==this.form.username){
             item.username=this.form.username;
              this.dialogVisible = false;
              return;
           }
         });
      }
    },
界面

添加對(duì)話框
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • ??JavaScript 與 HTML 之間的交互是通過(guò)事件實(shí)現(xiàn)的。 ??事件,就是文檔或?yàn)g覽器窗口中發(fā)生的一些特...
    霜天曉閱讀 3,684評(píng)論 1 11
  • ¥開啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個(gè)線程,因...
    小菜c閱讀 7,317評(píng)論 0 17
  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴(yán)謹(jǐn) 對(duì)...
    cosWriter閱讀 11,632評(píng)論 1 32
  • 一、Python簡(jiǎn)介和環(huán)境搭建以及pip的安裝 4課時(shí)實(shí)驗(yàn)課主要內(nèi)容 【Python簡(jiǎn)介】: Python 是一個(gè)...
    _小老虎_閱讀 6,319評(píng)論 0 10
  • 我放學(xué)回來(lái),在院子里喊“奶奶”, 奶奶說(shuō):快進(jìn)來(lái),今天有新鮮的大西瓜。 沙瓤的西瓜,真甜呀! 我春游回來(lái),在院子里...
    如蘇打小餅般干脆閱讀 456評(píng)論 0 8

友情鏈接更多精彩內(nèi)容