微信小程序 van-sticky + swiper + scroll-view + DropdownMenu + TreeSelect 实现顶部固定、可滑动/滚动/点击切换、选择地区、刷新、分页加载

本文介绍了如何在微信小程序中结合van-sticky、swiper、scroll-view、DropdownMenu和TreeSelect,实现顶部固定效果、滑动切换、点击选择地区以及刷新和分页加载功能。详细阐述了js、wxml和wxss的实现代码结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 一、如图:

  二、js:

import {
  getArea,
  getProductList
} from "../../../../../api/dsxapi";
const ui = require("../../../../../utils/ui");
Page({
  data: {
    navData: ['法律', '财税', '投融资', '知识产权', '企业产业链', '园区招商', '综合业务'],
    currentTab: 0, //标签下标
    navScrollLeft: 0,
    itemTitle: "服务地区",
    mainActiveIndex: 0,
    activeId: null,
    items: null,
    province: '', //省
    provinceId: null, //省份id
    marketId: null, //市id
    ProductList: [], //产品列表
    pages: 0,
    current: 1,
    top: 0
  },
  onLoad(options) {
    // 滚动
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          windowWidth: res.windowWidth
        })
      },
    })
  },
  onShow() {
    this.ObtainArea()
    this.ObtainProductList(this.data.current)
  },

  //获取地区
  ObtainArea() {
    getArea().then((res) => {
      let ress = res.data.map((item) => {
        return {
          text: item.areaName,
          id: item.areaId,
          children: [{
              text: '全部',
              id: -1
            },
            ...item.children.map((items) => {
              return {
                text: items.areaName,
                id: items.areaId
              }
            })
          ]
        }
      })
      ress.unshift({
        text: "全国"
      });
      this.setData({
        items: ress
      })
    }).catch(function (imError) {})
  },

  //获取产品列表
  ObtainProductList(current) {
    let params
    let category
    if (this.data.currentTab == 0) {
      category = 100621
    } else if (this.data.currentTab == 1) {
      category = 100622
    } else if (this.data.currentTab == 2) {
      category = 100623
    } else if (this.data.currentTab == 3) {
      category = 100624
    } else if (this.data.currentTab == 4) {
      category = 100625
    } else if (this.data.currentTab == 5) {
      category = 100626
    } else if (this.data.currentTab == 6) {
      category = 100627
    }
    if (this.data.marketId !== null) {
      params = {
        category: category, //标签id
        provinceId: this.data.provinceId, //省id
        cityId: this.data.marketId, //市id
        current: current,
        searchId: 11,
        size: 100,
      };
    } else {
      params = {
        category: category, //标签id
        current: current,
        size: 20,
      };
    }
    getProductList(params).then((res) => {
      let ProductList
      if (res.data.current == 1) {
        ProductList = res.data.records;
        ProductList.forEach((item, index) => {
     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

D_evin_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值