strategy.vue 3.1 KB
<template>
  <LayoutApp title="咸鱼潮玩转攻略" :show-back="true" :back-action="goBack">
    <ul>
      <li v-for="(item, index) in imageList" :key="index">
        <div v-if="item.urls && item.urls.length > 0" class="link-container">
          <a href="javascript:;"
          :style="{left: linkItem.left, top: linkItem.top, width: linkItem.width, height: linkItem.height}"
          v-for="linkItem in item.urls"
          :key="linkItem.link"
          @click="jumpTo"
          :data-item="JSON.stringify(linkItem)"
          >
          </a>
        </div>
        <img :src="item.image" alt=""/>
      </li>
    </ul>
  </LayoutApp>
</template>

<script>
export default {
  name: 'Strategy',
  data() {
    return {
      imageList: [
        { image: '//cdn.yoho.cn/xianyu/gonglue/1.jpg?imageView2/2/w/750/format/jpg' },
        { image: '//cdn.yoho.cn/xianyu/gonglue/2.jpg?imageView2/2/w/750/format/jpg' },
        { image: '//cdn.yoho.cn/xianyu/gonglue/3.jpg?imageView2/2/w/750/format/jpg' },
        { image: '//cdn.yoho.cn/xianyu/gonglue/4.jpg?imageView2/2/w/750/format/jpg',
          urls: [
            {
              left: '1.25rem',
              top: '4.5rem',
              width: '7.75rem',
              height: '5.25rem',
              linkName: 'ChannelPage',
              subName: ''
            }
          ]
        },
        { image: '//cdn.yoho.cn/xianyu/gonglue/5.jpg?imageView2/2/w/750/format/jpg',
          urls: [
            {
              linkName: 'strategySub',
              subName: 'qualityStandard',
              left: '1rem',
              top: '14rem',
              width: '17rem',
              height: '2.85rem'
            },
            {
              linkName: 'strategySub',
              subName: 'buyerPolicy',
              left: '2.5rem',
              top: '19rem',
              width: '6rem',
              height: '3rem'
            },
            {
              linkName: 'strategySub',
              subName: 'sellerPolicy',
              left: '10.8rem',
              top: '19rem',
              width: '6rem',
              height: '3rem'
            }
          ]
        }
      ]
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    jumpTo(event) {
      let linkItem = JSON.parse(event.currentTarget.dataset.item || '{}') || {};

      if (linkItem.subName === '') {
          this.$router.push({
            name: linkItem.linkName
        });
      } else {
        this.$router.push({
          name: linkItem.linkName,
          params: {
            subName: linkItem.subName,
          },
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
ul {
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 0;

  li {
    position: relative;
    width: 100%;
    overflow: hidden;

    img {
      width: 100%;
      float: left;
    }

    .link-container {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
      z-index: 9;

      a {
        position: absolute;
        display: block;
        width: 200px;
        height: 100px;
        background-color: transparent;
      }
    }
  }
}
</style>