欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue實(shí)現(xiàn)動(dòng)態(tài)添加或者刪除對(duì)象和對(duì)象數(shù)組的操作方法

 更新時(shí)間:2018年09月21日 11:29:52   作者:Moment ° 回憶 ✨  
這篇文章主要介紹了在Vue項(xiàng)目中實(shí)現(xiàn)動(dòng)態(tài)添加或者刪除對(duì)象和對(duì)象數(shù)組的操作方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

添加核心代碼如下:

this.data.push({
      type: [{
       value: '選項(xiàng)1',
       label: 'in'
      },
       {
        value: '選項(xiàng)3',
        label: 'out'
       }],
      value:[{
       value: '選項(xiàng)1',
       label: 'CSV'
      },
       {
        value: '選項(xiàng)3',
        label: 'TSV'
       }],
      parameter:'',
      default:'',
      description:'',
      isDelete:false,
     });

刪除核心代碼如下:

/*遍歷數(shù)組,然后根據(jù)選中的狀態(tài)獲取對(duì)應(yīng)的下標(biāo),然后進(jìn)行刪除*/
     for (let i = 0;i<this.data.length;i++){
      let obj = this.data[i];
      if (obj.isDelete){
       this.data.splice(i,1);
       i--
      }
     }

全部代碼如下:

<template>
  <div>
   ============================32、在Vue項(xiàng)目中實(shí)現(xiàn)動(dòng)態(tài)添加或者刪除對(duì)象和對(duì)象數(shù)組============================
   <div>
    <el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
    <el-button type="primary" icon="el-icon-delete" @click="deleteItem"></el-button>
    <el-row :gutter="50"  v-for="(item,index) in data" :key="index">
     <!--Type-->
     <el-col :span="4">
      <div class="grid-content bg-purple">
       <el-row >
        <el-col :span="24">
         <el-select v-model="value" placeholder="請(qǐng)選擇" size="mini">
          <el-option
           v-for="obj in item.type"
           :key="obj.value"
           :label="obj.label"
           :value="obj.value">
          </el-option>
         </el-select>
        </el-col>
       </el-row >
      </div>
     </el-col>
     <!--value-->
     <el-col :span="4">
      <div class="grid-content bg-purple-light">
       <el-row >
        <el-col :span="24">
         <el-select v-model="value" placeholder="請(qǐng)選擇" size="mini">
          <el-option
           v-for="obj in item.value"
           :key="obj.value"
           :label="obj.label"
           :value="obj.value">
          </el-option>
         </el-select>
        </el-col>
       </el-row >
      </div>
     </el-col>
     <!--Parameter-->
     <el-col :span="4">
      <div class="grid-content bg-purple">
       <el-input
        size="mini"
        placeholder="請(qǐng)輸入內(nèi)容"
        v-model="item.parameter"
        clearable>
       </el-input>
      </div>
     </el-col>
     <!--Default-->
     <el-col :span="4">
      <div class="grid-content bg-purple-light">
       <el-input
        size="mini"
        placeholder="請(qǐng)輸入內(nèi)容"
        v-model="item.default"
        clearable>
       </el-input>
      </div>
     </el-col>
     <!--Description-->
     <el-col :span="4">
      <div class="grid-content bg-purple">
       <el-input
        size="mini"
        placeholder="請(qǐng)輸入內(nèi)容"
        v-model="item.description"
        clearable>
       </el-input>
      </div>
     </el-col>
     <!--Del-->
     <el-col :span="4">
      <div class="grid-content bg-purple-light " id="checkboxSpacingDiv">
       <!-- `checked` 為 true 或 false -->
       <el-checkbox v-model="item.isDelete" size="medium"></el-checkbox>
      </div>
     </el-col>
    </el-row>
   </div>
  </div>
</template>
<script>
  export default {
    name: "VueArrays_32",
   data(){
     return {
      data:[
       {
        type: [{
         value: '選項(xiàng)1',
         label: 'in'
        },
         {
          value: '選項(xiàng)3',
          label: 'out'
         }],
        value:[{
         value: '選項(xiàng)1',
         label: 'CSV'
        },
         {
          value: '選項(xiàng)3',
          label: 'TSV'
         }],
        parameter:'',
        default:'',
        description:'',
        isDelete:false,
       },
      ],
     }
   },
   methods:{
    add(){
     this.data.push({
      type: [{
       value: '選項(xiàng)1',
       label: 'in'
      },
       {
        value: '選項(xiàng)3',
        label: 'out'
       }],
      value:[{
       value: '選項(xiàng)1',
       label: 'CSV'
      },
       {
        value: '選項(xiàng)3',
        label: 'TSV'
       }],
      parameter:'',
      default:'',
      description:'',
      isDelete:false,
     });
    },
    deleteItem(){
     /*遍歷數(shù)組,然后根據(jù)選中的狀態(tài)獲取對(duì)應(yīng)的下標(biāo),然后進(jìn)行刪除*/
     for (let i = 0;i<this.data.length;i++){
      let obj = this.data[i];
      if (obj.isDelete){
       this.data.splice(i,1);
       i--
      }
     }
    }
   }
  }
</script>
<style scoped>
</style>

 效果圖如下:

總結(jié)

以上所述是小編給大家介紹的Vue實(shí)現(xiàn)動(dòng)態(tài)添加或者刪除對(duì)象和對(duì)象數(shù)組的操作方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • vue 項(xiàng)目中的this.$get,this.$post等$的用法案例詳解

    vue 項(xiàng)目中的this.$get,this.$post等$的用法案例詳解

    vue.js的插件應(yīng)該暴露一個(gè)install方法。這個(gè)方法的第一個(gè)參數(shù)是vue構(gòu)造器,第二個(gè)參數(shù)是一個(gè)可選的選項(xiàng)對(duì)象,首頁要安裝axios,本文結(jié)合案例代碼給大家詳細(xì)講解vue 中的this.$get,this.$post等$的用法,一起學(xué)習(xí)下吧
    2022-12-12
  • vue手寫<RouterLink/>組件實(shí)現(xiàn)demo詳解

    vue手寫<RouterLink/>組件實(shí)現(xiàn)demo詳解

    這篇文章主要為大家介紹了vue手寫<RouterLink/>組件實(shí)現(xiàn)demo詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • Nuxt使用Vuex解讀

    Nuxt使用Vuex解讀

    這篇文章主要介紹了Nuxt使用Vuex的方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vue如何在main.js中配置全局的通用公共組件

    vue如何在main.js中配置全局的通用公共組件

    這篇文章主要介紹了vue如何在main.js中配置全局的通用公共組件問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Vue?Echarts實(shí)現(xiàn)實(shí)時(shí)大屏動(dòng)態(tài)數(shù)據(jù)顯示

    Vue?Echarts實(shí)現(xiàn)實(shí)時(shí)大屏動(dòng)態(tài)數(shù)據(jù)顯示

    同大多數(shù)的前端框架一樣,先讀官網(wǎng)的使用方法。學(xué)會(huì)基本使用后,在實(shí)例中找到自己想要demo。拿過來改一改,一個(gè)echarts圖表就形成,畢竟人家做就是為了方便使用,這篇文章主要介紹了Vue?Echarts實(shí)現(xiàn)實(shí)時(shí)大屏動(dòng)態(tài)數(shù)據(jù)顯示
    2022-10-10
  • vue中input標(biāo)簽上傳本地文件或圖片后獲取完整路徑的解決方法

    vue中input標(biāo)簽上傳本地文件或圖片后獲取完整路徑的解決方法

    本文給大家介紹vue中input標(biāo)簽上傳本地文件或圖片后獲取完整路徑,如E:\medicineOfCH\stageImage\xxx.jpg,本文給大家分享完美解決方案,感興趣的朋友跟隨小編一起看看吧
    2023-04-04
  • 使用vant-picker實(shí)現(xiàn)自定義內(nèi)容,根據(jù)內(nèi)容添加圖標(biāo)

    使用vant-picker實(shí)現(xiàn)自定義內(nèi)容,根據(jù)內(nèi)容添加圖標(biāo)

    這篇文章主要介紹了使用vant-picker實(shí)現(xiàn)自定義內(nèi)容,根據(jù)內(nèi)容添加圖標(biāo),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • element-ui中el-input只輸入數(shù)字(包括整數(shù)和小數(shù))

    element-ui中el-input只輸入數(shù)字(包括整數(shù)和小數(shù))

    開發(fā)中有時(shí)候需要input只能輸入數(shù)字,下面這篇文章主要給大家介紹了關(guān)于element-ui中el-input只輸入數(shù)字(包括整數(shù)和小數(shù))的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • vue中的自定義分頁插件組件的示例

    vue中的自定義分頁插件組件的示例

    這篇文章主要介紹了vue中的自定義分頁插件組件的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08
  • Composition API思想封裝NProgress示例詳解

    Composition API思想封裝NProgress示例詳解

    這篇文章主要為大家介紹了Composition API思想封裝NProgress示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08

最新評(píng)論