zw-swiper - 副本.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <u-swiper bg-color="transparent"
  3. :mode="list && list.length > 1 ?'round': 'none'"
  4. :list="list" :height="height"
  5. @click="openSwiper">
  6. </u-swiper>
  7. </template>
  8. <script>
  9. import {
  10. getBannerList
  11. } from "@/api/government.js"
  12. export default {
  13. name: "zw-swiper",
  14. props: {
  15. autoLoad: {
  16. type: Boolean,
  17. default: true
  18. },
  19. height: {
  20. type: Number,
  21. default: 200
  22. },
  23. StorageKey: {
  24. type: String,
  25. default: ""
  26. },
  27. keyword: {
  28. type: String,
  29. default: ""
  30. },
  31. },
  32. data() {
  33. return {
  34. list: []
  35. };
  36. },
  37. created() {
  38. },
  39. methods: {
  40. init() {
  41. this.getBanner(this.keyword)
  42. },
  43. // 获取 banner
  44. getBanner(keyword) {
  45. if (!keyword) return
  46. getBannerList(keyword).then(res => {
  47. const data = res.data || []
  48. this.list = data.map(el => {
  49. el.image = this.$getImgPath(el.image)
  50. return el
  51. });
  52. // this.list.map(item => {
  53. // item.image = this.$getImgPath(item.image)
  54. // })
  55. uni.setStorage({
  56. key: this.StorageKey,
  57. data: this.list,
  58. success: function() {
  59. console.log('success');
  60. }
  61. });
  62. console.log('')
  63. });
  64. },
  65. // 点击轮播图
  66. openSwiper(e) {
  67. this.$openPage(this.list[e])
  68. },
  69. },
  70. watch: {
  71. keyword: {
  72. handler: function(newKwd, oldKod) {
  73. if (oldKod === undefined) {
  74. uni.getStorage({
  75. key: this.StorageKey,
  76. success: res => {
  77. this.list = res.data || []
  78. }
  79. });
  80. }
  81. if (this.autoLoad && newKwd && newKwd !== oldKod) this.getBanner(newKwd)
  82. },
  83. immediate: true,
  84. deep: true
  85. }
  86. }
  87. }
  88. </script>
  89. <style>
  90. </style>