123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <template>
- <u-swiper bg-color="transparent"
- :mode="list && list.length > 1 ?'round': 'none'"
- :list="list" :height="height"
- @click="openSwiper">
- </u-swiper>
- </template>
- <script>
- import {
- getBannerList
- } from "@/api/government.js"
- export default {
- name: "zw-swiper",
- props: {
- autoLoad: {
- type: Boolean,
- default: true
- },
- height: {
- type: Number,
- default: 200
- },
- StorageKey: {
- type: String,
- default: ""
- },
- keyword: {
- type: String,
- default: ""
- },
- },
- data() {
- return {
- list: []
- };
- },
- created() {
- },
- methods: {
- init() {
- this.getBanner(this.keyword)
- },
- // 获取 banner
- getBanner(keyword) {
- if (!keyword) return
- getBannerList(keyword).then(res => {
- const data = res.data || []
- this.list = data.map(el => {
- el.image = this.$getImgPath(el.image)
- return el
- });
- // this.list.map(item => {
- // item.image = this.$getImgPath(item.image)
- // })
- uni.setStorage({
- key: this.StorageKey,
- data: this.list,
- success: function() {
- console.log('success');
- }
- });
- console.log('')
- });
- },
- // 点击轮播图
- openSwiper(e) {
- this.$openPage(this.list[e])
- },
- },
- watch: {
- keyword: {
- handler: function(newKwd, oldKod) {
- if (oldKod === undefined) {
- uni.getStorage({
- key: this.StorageKey,
- success: res => {
- this.list = res.data || []
- }
- });
- }
- if (this.autoLoad && newKwd && newKwd !== oldKod) this.getBanner(newKwd)
- },
- immediate: true,
- deep: true
- }
- }
- }
- </script>
- <style>
- </style>
|