imagePreview.vue 1.52 KB
<template>
  <div class="imagePreview">
    <template v-if="item">
      <van-image-preview v-model="show" :images="item" @change="change" :show-index="false" :start-position="index" ref="preview" asyncClose></van-image-preview>
      <template v-if="textStyle">
        <div class="text" :style="textStyle">
          {{ experience }}
        </div>
      </template>
    </template>
  </div>
</template>

<script type="text/ecmascript-6">
import { ImagePreview } from 'vant'
export default {
  name: 'imagePreview',
  components: {
    [ImagePreview.Component.name]: ImagePreview.Component
  },
  data () {
    return {
      textStyle: '',
      experience: '',
      item: [],
      show: true,
      index: 0
    }
  },
  activated () {
    let { item, index, experience } = this.getParams()
    if (item && item.length) {
      this.item = item
      this.experience = experience
      this.index = index
      document.title = `${index + 1}/${item.length}`
      setTimeout(() => {
        this.textStyle = `z-index:${Number(this.$refs.preview.$el.style.zIndex + 1)}`
      }, 1e3)
    } else this.to('crowdfunding')
  },
  mounted () {
  },
  methods: {
    change (e) {
      document.title = `${e + 1}/${this.item.length}`
    }
  }
}
</script>

<style scoped lang="scss">
.imagePreview {
  position: relative;
  width: 100vw;
  height: 100vh;
  .text {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    font-size: 14px;
    color: #ffffff;
    padding: 16px 16px 50px;
    box-sizing: border-box;
    z-index: 2;
  }
}
</style>