ad.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div class="ad-container" v-if="list.length > 0">
  3. <a class="ad-list-item" v-for="(item, index) in list" :key="index" @click="tj" :href="item.url" :style="{
  4. 'background-image': `url('${item.image}')`
  5. }" target="view_window">
  6. </a>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. props: ['location'],
  12. data() {
  13. return {
  14. list: []
  15. }
  16. },
  17. mounted() {
  18. this.fetchData()
  19. },
  20. methods: {
  21. getPagePath() {
  22. const link = location.href
  23. },
  24. tj()
  25. {
  26. this.$axios.$get("https://proginn-click.cn-hangzhou.log.aliyuncs.com/logstores/click/track_ua.gif?APIVersion=0.6.0&type=开发者首页广告");
  27. },
  28. async fetchData() {
  29. let res = await this.$axios.post('/uapi/pub/adInfo', {
  30. position: this.location
  31. })
  32. if (Number(res.data.status) === 1) {
  33. this.list = [...res.data.data.list]
  34. } else {
  35. this.$message.error(res.data.info);
  36. }
  37. }
  38. }
  39. }
  40. </script>
  41. <style lang="scss" scoped>
  42. .ad-container {
  43. // margin: 0 16px;
  44. }
  45. .ad-list-item {
  46. margin: 16px 0;
  47. display: block;
  48. padding-bottom: 75%;
  49. background-size: cover;
  50. background-position: center;
  51. background-repeat: no-repeat;
  52. cursor: pointer;
  53. &:first-child {
  54. margin-top: 0
  55. }
  56. &:last-child {
  57. margin-bottom: 0;
  58. }
  59. }
  60. .ad-tips {
  61. padding: 16px 0;
  62. font-size: 12px;
  63. text-align: center;
  64. color: #999;
  65. }
  66. </style>