1. 程式人生 > 實用技巧 >VUE element ui根據陣列生成多個互不干擾的下拉選單並獲取對應引數

VUE element ui根據陣列生成多個互不干擾的下拉選單並獲取對應引數

直接放效果圖和程式碼
效果圖:
  1.預設初始效果

  2.選擇後效果

程式碼

<template>
  <basic-container>
    <h2>VUE element ui根據陣列生成多個互不干擾的下拉選單並獲取對應引數</h2>
      <el-row>
          <el-col>
            <el-button @click="aaa">輸出下拉陣列</el-button>
          </el-col>
      </el-row>

      <el-row :gutter="
12"> <el-col :span="6" v-for="(item,index) in imgList" style="padding-top: 10px;"> <el-card style="width: 100%; height: 280px;" :body-style="{ padding: '0px' ,width:'100%',height:'100%', display: 'flex',cursor:'pointer'}" shadow="hover"> <div style="
position: relative; width: 100%;" class="check_box"> <el-dropdown @command="sumTypeCkeck" @visible-change="set_index(index)" style="position: absolute;right: 10px; top: 5px; z-index: 1;"> <span class="el-dropdown-link" style="color: #FFFFFF;"> {{sumType[index]}}
<i class="el-icon-arrow-down el-icon--right"></i> </span> <el-dropdown-menu slot="dropdown"> <el-dropdown-item v-for="(item,index) in sumTypeArray[index]" v-text="item" :command="item"></el-dropdown-item> </el-dropdown-menu> </el-dropdown> <el-image :src="item.img" onerror="this.style.display='none'" style="max-height: 100%;max-width: 100%;left: 50%;top: 50%;transform: translate(-50%,-50%)"> </el-image> <div style="font-size: 16px;position: absolute;bottom: 0; background-color: rgba(150, 150, 150, 0.35); height: 30px; width: 100%; text-align: center; line-height: 30px;color: yellow;">{{item.title}}</div> </div> </el-card> </el-col> </el-row> </basic-container> </template> <script> import ThreeDmodel from '../../components/4D/3Dmodel.vue' export default { components: { ThreeDmodel }, data() { return { imgList: [], //顯示牆面的陣列 index:0, //第幾個下拉框 sumTypeArray: [[0,1, 2, 3, 4, 5],[0,9,10],[0,110,120],[0,119,911],[0,5,4],[0,3,8],[0,41,514]],//下拉引數值 sumType: [], //選中(預設)值 }; }, mounted() { for (var i = 0; i < 6; i++) { this.imgList.push({ title: i + 1 + '', img: 'http://192.168.10.67:8000/media/77/test/images/ABC%E5%A1%94%E6%A5%BC%E7%AB%8B%E9%9D%A220120824_t3_2/glass/C-LM-02-11-20.png' }) } for(var i=0;i<this.imgList.length;i++){ this.sumType.push(0) } }, methods: { sumTypeCkeck(type) { this.sumType[this.index] = type this.sumType=[...this.sumType]//ES6拓展運算子生成新的props物件 // console.log(type) // console.log(this.index) }, set_index(index) { this.index = index }, aaa(){ console.log(this.sumType) }, }, } </script> <style> </style>