el-image动态预览,initial-index动态更换为当前点击的图片下标

  • Post author:
  • Post category:其他


<template>
  <div>
    <el-card class="box-card">
      <div>施工前检测</div>
    </el-card>
    <div class="m-4">
      <el-form
        :inline="true"
        :model="form"
        label-width="80px"
        class="demo-form-inline"
        label-position="left"
      >
        <div class="flex">
          <el-form-item label="版面尺寸">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="杆件尺寸">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
        </div>
        <el-form-item label="备注" class="w50">
          <el-input
            type="textarea"
            v-model="form.name"
            rows="5"
            show-word-limit
            maxlength="200"
            placeholder=""
            class="w100"
          ></el-input>
        </el-form-item>
        <el-form-item label="施工照片" class="w50">
          <div class="flex">
            <el-image
              @click="handlePictureCardPreview(item)"  //增加一个点击预览方法获取当前点击的图片主体
              v-for="item in srcList"
              :key="item"
              :src="item"
              :zoom-rate="1.2"
              style="width: 100px; height: 100px; margin-right: 10px"
              :preview-src-list="srcList"
              :initial-index="srcIndex" //定义一个srcIndex变量
              fit="cover"
            />
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  name: 'pending',
  data() {
    return {
      form: {
        name: '',
      },
      srcIndex: 0,
      srcList: [
        'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
        'https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg',
        'https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg',
        'https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg',
        'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
        'https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg',
        'https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg',
      ],
    }
  },
  created() {},
  mounted: function () {},

  methods: {
    handlePictureCardPreview(item) {
      this.srcIndex = this.srcList.indexOf(item)  //动态获取下标
    },
  },
}
</script>

<style lang="scss" scoped>
.box-card {
  line-height: 20px;
  background-color: #f6f6f6;
}
</style>



版权声明:本文为weixin_52934055原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。