ut-ad-item.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <!-- 轮播图 -->
  3. <view class="swiper-item" @click.stop="adRoute">
  4. <image class="swiper-img" :src="item?.adImg" mode="heightFix" />
  5. </view>
  6. </template>
  7. <script setup lang="ts" name="ad-item">
  8. // 移除了不必要的ref导入
  9. interface AdItem {
  10. adImg: string;
  11. adType: string;
  12. adUrl: string;
  13. }
  14. interface Props {
  15. item: AdItem;
  16. index: number;
  17. count: number;
  18. }
  19. const props = withDefaults(defineProps<Props>(), {
  20. item: () => ({} as AdItem),
  21. index: 0,
  22. count: 1
  23. });
  24. const adRoute = () => {
  25. if (props.item?.adType == '1') {
  26. uni.$u.route({
  27. type: 'navigateTo',
  28. url: props.item?.adUrl,
  29. params: {
  30. ad: 1
  31. }
  32. });
  33. }
  34. if (props.item?.adType == '2') {
  35. uni.$u.route({
  36. type: 'navigateTo',
  37. url: '/pages/tool/webview/index',
  38. params: {
  39. url: props.item?.adUrl
  40. }
  41. });
  42. }
  43. };
  44. </script>
  45. <style lang="scss" scoped>
  46. .swiper-item {
  47. position: absolute;
  48. left: 0;
  49. top: 0;
  50. right: 0;
  51. bottom: 0;
  52. height: 100%;
  53. display: flex;
  54. align-items: center;
  55. justify-content: center;
  56. overflow: hidden;
  57. }
  58. .swiper-img {
  59. width: 100%;
  60. height: 100%;
  61. }
  62. </style>