亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

element的el-form和el-table嵌套使用實現(xiàn)

 更新時間:2022年08月12日 10:02:16   作者:ddx2019  
本文主要介紹了element的el-form和el-table嵌套使用實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

一、element的el-form和el-table嵌套使用

要點:

  • :model="addJsonForm" 給表單綁定數(shù)據(jù),addJsonForm 是傳入表單的數(shù)據(jù)對象
  • 注意表單數(shù)據(jù)對象 addJsonForm 的定義:屬性 params (可按需求命名)為表單內嵌套的表格的顯示數(shù)據(jù),數(shù)組類型; 屬性 addJsonRules ,為表單綁定的驗證規(guī)則。
  • el-table: 采用自定義列模板,可自定義表頭, el-form: 表單項綁定對應的字段名和校驗規(guī)則
  • :prop="'params.' + scope.$index + '.name'" 綁定傳入Form 組件的 model 中對應的字段 name
  • :rules="addJsonForm.addJsonRules.name" 綁定表單驗證規(guī)則
<template>
  <div>
    <el-form
      :model="addJsonForm"
      ref="addJsonForm"
      :rules="addJsonForm.addJsonRules"
      :inline="true"
      label-width="108px"
    >
      <el-table :data="addJsonForm.params" style="width: 100%" border>
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>

        <el-table-column align="center">
          <template slot="header" slot-scope="scope">
            <span style="color:#2d65dc;">成員名稱</span>
            <i style="color:#F56C6C;">*</i>
          </template>
          <template slot-scope="scope">
            <el-form-item
              :prop="'params.' + scope.$index + '.name'"
              :rules="addJsonForm.addJsonRules.name"
            >
              <el-input
                type="text"
                v-model="scope.row.name"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column align="center">
          <template slot="header" slot-scope="scope">
            <span style="color:#2d65dc;">成員值</span>
            <i style="color:#F56C6C;">*</i>
          </template>
          <template slot-scope="scope">
            <el-form-item
              :prop="'params.' + scope.$index + '.value'"
              :rules="addJsonForm.addJsonRules.value"
            >
              <el-input
                type="text"
                v-model="scope.row.value"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      addJsonForm: {
        params: [
          {
            name: "",
            value: ""
          }
        ],
        addJsonRules: {
          name: [
            { required: true, message: "請輸入成員名稱", trigger: "blur" }
          ],
          value: [
            { required: true, message: "成員值不能為空", trigger: "blur" }
          ]
        }
      }
    };
  }
};
</script>

二、應用實例

點擊添加的時候,動態(tài)增加表格的行數(shù),點擊刪除的時候,刪除表格的行數(shù)據(jù)。

近期更新: 因評論區(qū)問到后續(xù)如何用 Form 表單的 resetFields 方法,這里就新加一個重置功能。

<template>
  <div>
    <el-button @click="showPopup">點擊顯示彈框</el-button>
    <h3>
      dataSourceJson: <span>{{ FormInAddPopup.dataSourceJson }}</span>
    </h3>
    <el-dialog
      class="comn_dialog"
      title="添加數(shù)據(jù)"
      :visible.sync="addJsonVisible"
      width="415px"
      top="23vh"
    >
      <el-button @click="addTableItem">添加</el-button>
      <el-button @click="delTableItem">刪除</el-button>
      /* 近期更新 */
      <el-button @click="resetForm('myForm')">重置</el-button> 
      <el-form
        :model="addJsonForm"
        ref="addJsonForm"
        :rules="addJsonForm.addJsonRules"
        :inline="true"
        label-width="108px"
      >
        <el-table
          :data="addJsonForm.params"
          style="width: 100%"
          border
          @selection-change="addJsonSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center">
          </el-table-column>

          <el-table-column align="center">
            <template slot="header" slot-scope="scope">
              <span style="color:#2d65dc;">成員名稱</span>
              <i style="color:#F56C6C;">*</i>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'params.' + scope.$index + '.name'"
                :rules="addJsonForm.addJsonRules.name"
              >
                <el-input
                  type="text"
                  v-model="scope.row.name"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot="header" slot-scope="scope">
              <span style="color:#2d65dc;">成員值</span>
              <i style="color:#F56C6C;">*</i>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'params.' + scope.$index + '.value'"
                :rules="addJsonForm.addJsonRules.value"
              >
                <el-input
                  type="text"
                  v-model="scope.row.value"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetAddJsonPopup">取 消</el-button>
        <el-button type="primary" @click="submitAddJsonPopup">確定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      addJsonVisible: false,
      addJsonMultiple: [],
      FormInAddPopup: {
        dataSourceJson: "" // 獲取到的dataJson,顯示為 [{name:"",value:""},{name:"",value:""}] 的格式
      },
      tabItemId: 1, // 表格數(shù)據(jù)的 id
      addJsonForm: {
        params: [
          {
            name: "",
            value: "",
            tabItemId: 1 // 彈框中,刪除空行的唯一標志,默認從1開始
          }
        ],
        addJsonRules: {
          name: [
            { required: true, message: "請輸入成員名稱", trigger: "blur" }
          ],
          value: [
            { required: true, message: "成員值不能為空", trigger: "blur" }
          ]
        }
      }
    };
  },
  methods: {
  // 近期更新
    resetForm(formName) {
      this.$refs[formName].resetFields();
   },
    RndNum(n) {
      // 生成隨機數(shù)
      let rdmNum = "";
      for (let i = 0; i < n; i++) {
        rdmNum += Math.floor(Math.random() * 10); // [0,10)的整數(shù)
      }
      return rdmNum;
    },
    showPopup() {
      
      this.addJsonVisible = true;
    },
    addJsonSelectionChange(val) {
      this.addJsonMultiple = val;
    },
    resetAddJsonPopup() {
      //關閉 固定值彈窗
      this.$set(this.addJsonForm, "params", []);
      this.addJsonVisible = false;
    },
    submitAddJsonPopup() {
      //保存 固定值
      if (this.addJsonMultiple.length > 0) {
        this.$refs["addJsonForm"].validate(valid => {
          if (valid) {
            let result = [];
            this.addJsonMultiple.map(val => {
              this.$delete(val, "tabItemId"); // 刪除tabItemId屬性
              result.push(val);
            });
            result.length ? (result = JSON.stringify(result)) : (result = "");
            this.FormInAddPopup.dataSourceJson = result;
            this.addJsonVisible = false;
          } else {
            return false;
          }
        });
      } else {
        this.$message.warning("請選擇要保存的數(shù)據(jù)");
      }
    },
    addTableItem() {
      this.tabItemId = "T" + this.RndNum(6); //生成以T開頭的七位隨機數(shù)
      this.addJsonForm.params.push({
        name: "",
        value: "",
        tabItemId: this.tabItemId
      });
    },

    delTableItem() {
      // 確認刪除
      if (this.addJsonMultiple.length > 0) {
        let arrs = [];
        let ids = this.addJsonMultiple.map(val => val.tabItemId); //拿到選中的數(shù)據(jù)id,
        this.addJsonForm.params.forEach(item => {
          if (!ids.includes(item.tabItemId)) {
            // 當id在params中,表示數(shù)據(jù)被選中,該將其刪除,即將不被選中的保留
            arrs.push(item);
          }
        });
        this.addJsonForm.params = arrs;
      } else {
        this.$message.warning("請選擇要刪除的數(shù)據(jù)");
      }
    }
  }
};
</script>

到此這篇關于element的el-form和el-table嵌套使用實現(xiàn)的文章就介紹到這了,更多相關element el-form和el-table嵌套內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 詳解axios 全攻略之基本介紹與使用(GET 與 POST)

    詳解axios 全攻略之基本介紹與使用(GET 與 POST)

    本篇文章主要介紹了axios 全攻略之基本介紹與使用(GET 與 POST),詳細的介紹了axios的安裝和使用,還有 GET 與 POST方法,有興趣的可以了解一下
    2017-09-09
  • Vue 中對圖片地址進行拼接的方法

    Vue 中對圖片地址進行拼接的方法

    今天小編就為大家分享一篇Vue 中對圖片地址進行拼接的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue淺拷貝和深拷貝實現(xiàn)方案

    Vue淺拷貝和深拷貝實現(xiàn)方案

    在理解淺拷貝和深拷貝淺前,必須先理解基本數(shù)據(jù)類型和引用數(shù)據(jù)類型的區(qū)別,這篇文章主要介紹了Vue淺拷貝和深拷貝實現(xiàn)方案及區(qū)別對比分析,需要的朋友可以參考下
    2023-03-03
  • vue編寫的功能強大的swagger-ui頁面及使用方式

    vue編寫的功能強大的swagger-ui頁面及使用方式

    swagger是一種標準的數(shù)據(jù)格式的定義,對于不同語言進行實現(xiàn)一些注解API式的東西,能快速生成這種描述restful格式的api信息的json串,本文給大家詳細介紹vue編寫的功能強大的swagger-ui頁面,感興趣的朋友跟隨小編一起看看吧
    2022-02-02
  • vue實現(xiàn)右鍵菜單欄

    vue實現(xiàn)右鍵菜單欄

    這篇文章主要為大家詳細介紹了vue實現(xiàn)右鍵菜單欄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • 詳解Vue 開發(fā)模式下跨域問題

    詳解Vue 開發(fā)模式下跨域問題

    本篇文章主要介紹了Vue 開發(fā)模式下跨域問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • Vue路由切換時的左滑和右滑效果示例

    Vue路由切換時的左滑和右滑效果示例

    這篇文章主要介紹了Vue路由切換時的左滑和右滑效果,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • vue實現(xiàn)圖片切換效果

    vue實現(xiàn)圖片切換效果

    這篇文章主要為大家詳細介紹了vue實現(xiàn)圖片切換效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • 前端Vue頁面中展示本地圖片簡單代碼示例

    前端Vue頁面中展示本地圖片簡單代碼示例

    今天遇到一個在vue文件中引入本地圖片的問題,于是有了這篇文章,本文主要給大家介紹了關于前端Vue頁面中展示本地圖片的相關資料,需要的朋友可以參考下
    2023-12-12
  • 利用Vue3實現(xiàn)拖拽定制化首頁功能

    利用Vue3實現(xiàn)拖拽定制化首頁功能

    vue3正式版已經發(fā)布大半年了,咱也得緊跟時代潮流,vue3帶來的很多改變,下面這篇文章主要給大家介紹了關于利用Vue3實現(xiàn)拖拽定制化首頁功能的相關資料,需要的朋友可以參考下
    2022-05-05

最新評論