swiper-baner.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="time" :duration="duration">
  3. <swiper-item v-for="(item, index) in imgList" :key="index" @click="itemClick(item)">
  4. <img class="img" :src="`http://192.168.0.45:9002${item.img}`" />
  5. </swiper-item>
  6. </swiper>
  7. </template>
  8. <script>
  9. import { mapActions, mapState } from 'vuex'
  10. export default {
  11. props: {
  12. // 自动播放间隔
  13. time: { type: Number, default: 2000 }
  14. },
  15. computed: {
  16. ...mapState(['imgList'])
  17. },
  18. data() {
  19. return {
  20. // 指示点
  21. indicatorDots: true,
  22. // 自动播放
  23. autoplay: true,
  24. // 幻灯片切换时长(动画时长)
  25. duration: 500,
  26. };
  27. },
  28. async mounted() {
  29. await this.imgQuery();
  30. },
  31. methods: {
  32. ...mapActions(['imgQuery']),
  33. async itemClick(e) {
  34. let path;
  35. // 栏目
  36. if (e.type == 1) path = `/pages/list/index?column=${e.column}`;
  37. // 单页
  38. if (e.type == 2) path = `/pages/details/index?pages=${e._pages}`;
  39. // 链接
  40. if (e.type == 0) {
  41. location.href = e.url;
  42. return;
  43. }
  44. console.log(path);
  45. uni.navigateTo({ url: path,
  46. success: res => {
  47. console.log(res, 'res');
  48. },
  49. fail: (err) => {
  50. console.log(err, 123);
  51. },
  52. complete: () => {
  53. console.log(231);
  54. }});
  55. }
  56. },
  57. };
  58. </script>
  59. <style lang="scss" scoped>
  60. .img {
  61. width: 100%
  62. }
  63. </style>