list-view-ad.uvue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <list-view @scrolltolower="onScrollTolower" style="flex:1" show-scrollbar=false>
  3. <list-item v-for="index in listcount" :type="(index != 0 && index%10 == 6) ? 0:1">
  4. <!-- #ifndef MP -->
  5. <ad v-if="index != 0 && index%10 == 6" adpid="1111111111" @load="onAdLoad" @error="onAdError" @close="onAdClose"></ad>
  6. <!-- #endif -->
  7. <!-- #ifdef MP -->
  8. <view class="uni-center">微信小程序平台暂不支持测试广告位,需要开通uni-ad后可测试</view>
  9. <!-- #endif -->
  10. <text v-if="index == 0 || index%10 != 6" style="width: 100%; height: 200px;background-color: aquamarine;margin-top: 10px;">这是一条占位的信息{{index}}</text>
  11. </list-item>
  12. </list-view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. listcount: 10
  19. }
  20. },
  21. methods: {
  22. onScrollTolower(_ : ScrollToLowerEvent) {
  23. setTimeout(() => {
  24. this.listcount = this.listcount + 10
  25. }, 300)
  26. },
  27. onAdLoad() {
  28. console.log("广告加载成功")
  29. uni.showToast({
  30. position: "center",
  31. title: "广告加载成功"
  32. })
  33. },
  34. onAdError(e : UniAdErrorEvent) {
  35. console.log("广告加载失败" + (e.detail))
  36. },
  37. onAdClose() {
  38. console.log("广告关闭了")
  39. }
  40. }
  41. }
  42. </script>