O elemento é conveniente para verificar o uso de. $ Set, posição da chave da imagem do banner

Protótipo de requisito: Insira a descrição da imagem aqui
Principais questões envolvidas:
1. Verificação de conveniência da lista
2. Esta função. $ Set transposta;
não há muito o que falar sobre o código, é conveniente para você e para mim

//主要代码
<el-form :model="formdata" ref="form" size="small" label-width="120px">
      <div v-for="(banner, i) in formdata.BannerList" :key="i">
        <el-col :span="6">
          <el-form-item
            :prop="'BannerList.' + i + '.IMAGE_URL'"
            label-width="0px"
          >
            <div class="thumb">
              <w-upload
                class="thumb-upload"
                :limit-size="10 * 1024 * 1024"
                :limit-size-message="'文件过大,请上传 10Mb 以内的文件'"
                :limit-ext="['jpg', 'jpeg', 'png', 'gif']"
                :ext-data="{ i }"
                :on-success="IMAGE_URL_handle"
              >
                <img
                  :src="banner.IMAGE_URL | downloadUrl"
                  v-if="banner.IMAGE_URL != ''"
                />
                <div class="thumb-cover" v-else>
                  <div class="thumb-btn">
                    <i class="el-icon-upload"></i>
                    点击上传图片
                  </div>
                </div>
              </w-upload>
            </div>
            <div class="text-center">
              <span class="mr10 cursor" @click="toUp(i)"
                ><i class="el-icon-top"></i>上移</span
              ><span class="mr10 cursor" @click="toBottom(i)"
                ><i class="el-icon-bottom"></i>下移</span
              ><span class="cursor" @click="deleteBanner(i)"
                ><i class="el-icon-delete"></i>删除</span
              >
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="18">
          <el-row :gutter="rowGutter">
            <el-col :span="12">
              <el-form-item
                label="名称"
                :prop="'BannerList.' + i + '.INTERMEDIARYCODE'"
              >
                <el-input
                  v-model="banner.INTERMEDIARYCODE"
                  placeholder="请输入名称"
                  :maxlength="100"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="发布机构"
                :prop="'BannerList.' + i + '.INTERMEDIARYNAME'"
              >
                <el-input
                  v-model="banner.INTERMEDIARYNAME"
                  placeholder="请输入中介人名称"
                  :maxlength="50"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="rowGutter">
            <el-col :span="12">
              <el-form-item
                label="许可证起期"
                :prop="'BannerList.' + i + '.LICENSE_START'"
              >
                <el-date-picker
                  v-model="banner.LICENSE_START"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择许可证起期"
                  type="date"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="许可证止期"
                :prop="'BannerList.' + i + '.LICENSE_END'"
              >
                <el-date-picker
                  v-model="banner.LICENSE_END"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择许可证止期"
                  type="date"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="rowGutter">
            <el-col :span="24">
              <el-form-item
                label="链接"
                :prop="'BannerList.' + i + '.PRODUCTURL'"
                :rules="formrule.PRODUCTURL"
              >
                <el-input
                  v-model="banner.PRODUCTURL"
                  placeholder="请输入链接"
                  :maxlength="100"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
      </div>
    </el-form>
 <script>
data() {
    
    
    return {
    
    
      rowGutter: 10,
        BannerList: [
          {
    
    
            INTERMEDIARYCODE: '123',
            INTERMEDIARYNAME: '123',
            LICENSE_START: '123',
            LICENSE_END: '123',
            PRODUCTURL: '',
            IMAGE_URL: '',
          },
          {
    
    
            INTERMEDIARYCODE: '456',
            INTERMEDIARYNAME: '456',
            LICENSE_START: '456',
            LICENSE_END: '456',
            PRODUCTURL: '',
            IMAGE_URL: '',
          },
          {
    
    
            INTERMEDIARYCODE: '789',
            INTERMEDIARYNAME: '789',
            LICENSE_START: '789',
            LICENSE_END: '789',
            PRODUCTURL: '',
            IMAGE_URL: '',
          },
        ],
      },
      formrule: {
    
    
        PRODUCTURL: [
          {
    
     required: false, message: '请填写链接地址' },
          {
    
    
            pattern: /(http|https|HTTP|HTTPS):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/,
            message: '请填写正确格式',
          },
        ],
      },
    };
  },
  methods: {
    
    
    IMAGE_URL_handle(res, file, fileList, extData) {
    
    
      console.log(res, file, fileList, extData);
    },
    toUp(index) {
    
    
      console.log('111111111', index);
      this.changeLocation('up', index);
    },
    toBottom(index) {
    
    
      console.log('222222222222222', index);
      this.changeLocation('bottom', index);
    },
    deleteBanner(index) {
    
    
      this.formdata.BannerList.splice(index, 1);
    },
    changeLocation(location, index) {
    
    
      console.log(location, index);
      if (location == 'up' && index > 0) {
    
    
        const tmp = this.formdata.BannerList[index];
        this.$set(
          this.formdata.BannerList,
          index,
          this.formdata.BannerList[index - 1]
        );
        this.$set(this.formdata.BannerList, index - 1, tmp);
        // this.formdata.BannerList[index] = this.formdata.BannerList[index - 1];
        // this.formdata.BannerList[index - 1] = tmp;
        console.log(this.formdata.BannerList);
      } else if (
        location == 'bottom' &&
        index < this.formdata.BannerList.length
      ) {
    
    
        const tmp = this.formdata.BannerList[index];
        this.$set(
          this.formdata.BannerList,
          index,
          this.formdata.BannerList[index + 1]
        );
        this.$set(this.formdata.BannerList, index + 1, tmp);
        console.log(this.formdata.BannerList);
      }
    },
  },
</script>

Se você apenas olhar para o método de verificação conveniente da lista primeiro, olhe diretamente aqui, o foco foi marcado como
Insira a descrição da imagem aqui
2. este uso de. $ Set

Acho que você gosta

Origin blog.csdn.net/lbchenxy/article/details/108621233
Recomendado
Clasificación