【菜狗学前端】uniapp(vue3|微信小程序)实现外卖点餐的左右联动功能

记录,避免之后忘记......

一、目的:实现左右联动

  1. 右->左 滚动(上拉/下拉)右侧,左侧对应品类选中
  2. 左->右 点击左侧品类,右侧显示对应品类

二、实现右->左 滚动(上拉/下拉)右侧,左侧对应品类选中

1.在data()中初始化需要用到的数据

须知:左侧哪个品类选中是根据trigger==index比较得出的

2.在onLoad()中调用getheight()获取右侧各品类高度,给this.heightset数组赋值

// 回调函数,在数据发生改变时,在渲染dom之后,回制动执行回调函数

// 获取不同分类的高度

this.$nextTick(()=>{

this.getheight()

})

getheight()函数:

// 获取右侧各分类高度

getheight(){

const query=wx.createSelectorQuery()

query.selectAll('.rig-height').boundingClientRect()

query.exec(res=>{

let height=0

res[0].forEach(item=>{

height = height+item.height

this.heightset.push(height)

})

console.log(this.heightset);

})

}

 打印结果:

3.给右侧<scroll-view>组件绑定滚动函数@scroll=”scrollRight”,根据实际滚动高度与当前品类高度比较结果改变trigger进而改变左侧选中品类。

// 右侧滚动触发

scrollRight(e){

// console.log(e.detail.scrollTop)//获取当前滚动实际高度

if(e.detail.scrollTop>=this.heightset[this.trigger]){//上拉到下一个品类

this.trigger++

}else{

if(e.detail.scrollTop<this.heightset[this.trigger-1]){//下拉到上一个品类

this.trigger--

}

}

}

三、实现左->右 点击左侧品类,右侧显示对应品类

1.使用scroll-view组件的scroll-into-view属性实现

2.给左侧各品类绑定点击函数,改变this.trigger和this.scroll_into

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-16 06:48:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-16 06:48:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-16 06:48:03       82 阅读
  4. Python语言-面向对象

    2024-06-16 06:48:03       91 阅读

热门阅读

  1. Qt 槽函数重载时通过函数指针绑定

    2024-06-16 06:48:03       38 阅读
  2. 常用的Linux、python命令

    2024-06-16 06:48:03       29 阅读
  3. 【学习笔记】MySQL(Ⅲ)

    2024-06-16 06:48:03       33 阅读
  4. 【手机】米10替换基带

    2024-06-16 06:48:03       33 阅读
  5. Cheat Engine.exe修改植物大战僵尸阳光与冷却

    2024-06-16 06:48:03       27 阅读
  6. 模拟题1(考虑周全以及情况较多)

    2024-06-16 06:48:03       34 阅读
  7. 深入理解Python闭包:概念、应用与示例

    2024-06-16 06:48:03       46 阅读
  8. 目录深度探索

    2024-06-16 06:48:03       24 阅读
  9. Leetcode.2601 质数减法运算

    2024-06-16 06:48:03       31 阅读
  10. Web前端图形显示:深入探索与实用指南

    2024-06-16 06:48:03       38 阅读
  11. seata源码分析(04)_TM开启全局事务

    2024-06-16 06:48:03       23 阅读
  12. 738. 单调递增的数字

    2024-06-16 06:48:03       33 阅读