ad.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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" :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. async fetchData() {
  25. let res = await this.$axios.post('/uapi/pub/adInfo', {
  26. position: this.location
  27. })
  28. if (Number(res.data.status) === 1) {
  29. this.list = [...res.data.data.list]
  30. } else {
  31. this.$message.error(res.data.info);
  32. }
  33. }
  34. }
  35. }
  36. </script>
  37. <style lang="scss" scoped>
  38. .ad-container {
  39. // margin: 0 16px;
  40. }
  41. .ad-list-item {
  42. margin: 16px 0;
  43. display: block;
  44. padding-bottom: 75%;
  45. background-size: cover;
  46. background-position: center;
  47. background-repeat: no-repeat;
  48. cursor: pointer;
  49. &:first-child {
  50. margin-top: 0
  51. }
  52. &:last-child {
  53. margin-bottom: 0;
  54. }
  55. }
  56. .ad-tips {
  57. padding: 16px 0;
  58. font-size: 12px;
  59. text-align: center;
  60. color: #999;
  61. }
  62. </style>