使用场景

举个栗子:外卖app当订单商品数量比较多时,不方便一次性展示出来。通常会展示一部分,并在页面给出一个查看更多功能。点击后即可自定义展示剩余内容,比如可以每次点击多展示N个内容,或展示所有。

实现效果

实现步骤

以下为整个页面的所有代码,涉及到的数据可以自己造一些,此处不再赘述。

vue页面

<template>
<view class="box">
<h3>订单信息</h3> <!-- 商品列表-->
<view class="productlist">
<block v-for="(item,index) in cartList" :key="index">
<view class="product" v-show="index < max">
<!-- 左边商品图片 -->
<view class="image">
<image :src="item.image" mode="aspectFill"></image>
</view>
<view class="info">
<text>{{item.name}}</text>
<text>x{{item.count}}</text>
</view>
<view class="price">
实付¥<text class="red-text">{{item.totalPrice}}</text>
</view>
</view>
</block>
<view style="text-align: center;color: #737373;" v-show="total > max" @tap="more">查看更多</view>
</view> <view class="summary">
<uni-list :border="true">
<view class="right-fixed">
合计:¥<text class="red-text">{{totalPrice}}</text>
</view>
<view class="receive">
<view>
<text>收货地址</text>
<text class="right-fixed">{{checkedAddress.address}}</text>
</view>
<view>
<text>收货人信息</text>
<text class="right-fixed">{{checkedAddress.receiver}} {{checkedAddress.contact}}</text>
</view>
<view>
<text>备注</text>
<!-- <text class="right-fixed">少放辣!</text> -->
<input type="text" name="remark" v-model="remark">
</view>
</view>
</uni-list>
</view> <button @click="pay" type="primary">立即支付</button>
</view>
</template>

JS

<script>
import {
mapState,
mapMutations
} from 'vuex' import {guid} from '../../util/util.js' export default {
data(){
return{
max: 3, //默认展示几条数据
remark: ''
}
},
components: { },
computed: {
...mapState(['cartList']),
...mapState({
checkedAddress: state => state.checkedAddr,
orderShopInfo: state => state.orderShopInfo
}),
// 计算所有商品总数量
totalCount() {
return this.cartList.reduce((total, item) => {
return total + item.count
}, 0)
},
// 所有商品累积的总价
totalPrice() {
let amount = this.cartList.reduce((total, item) => {
return total + item.totalPrice
}, 0)
// 加上配送费
return (Math.round((amount+this.orderShopInfo.physical) * 10) / 10).toFixed(1)
},
// 商品个数
total(){
return this.cartList.length
} },
methods: {
more() {
console.log(this.max)
this.max = this.total; //每次点击加1条
},
pay() {
let that = this
uni.showModal({
title: '提示',
content: '确定支付订单?',
success: function (res) {
if (res.confirm) {
// 遍历购物车中商品信息
let items = [];
that.cartList.forEach((item)=>{
let e = {
product_id: item.gid,
product_name: item.name,
image: item.image,
qty: item.count,
amount: item.totalPrice
} items.push(e)
}) //console.log(JSON.stringify(items)) let mydate = new Date();
// 构建订单实体
let order = {
userid: that.$store.state.loginUser._id,
order_no: 'sa'+guid(),
shop_id: that.orderShopInfo._id,
shop_name: that.orderShopInfo.shop,
shop_image: that.orderShopInfo.logo,
total_qty: that.totalCount,
total_amount: that.totalPrice,
deliver_fee: that.orderShopInfo.physical,
address: that.checkedAddress.address,
receiver: that.checkedAddress.receiver,
contact: that.checkedAddress.contact,
remark: that.remark,
order_time: mydate.toLocaleDateString()+' '+mydate.toLocaleTimeString(),
items: items
} console.log(order); // 提交订单
that.$post('/addOrder', JSON.stringify(order)).then(res => {
// 清空购物车
that.$store.commit('clearCart')
uni.showToast({
title:'添加成功!',
duration:1000
})
setTimeout(function () {
uni.switchTab({
url:'/pages/order/order'
})
}, 1000); })
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
}
}
</script>

CSS

<style lang="scss" scoped>
$base-color: red;
.red-text{
color: $base-color;
}
.box {
padding: 10px;
color: #898989;
} .productlist {
justify-content: space-between;
margin: 30upx 0;
color: #898989; .product {
height: 110px;
display: flex;
} .product .image {
width: 100px !important;
height: 100px !important;
overflow: hidden;
} .product .image image {
width: 100%;
height: 100%;
border-radius: 10upx;
overflow: hidden;
} .product .info {
width: 300upx;
line-height: 100px;
padding-left: 10px;
} .product .price {
position: fixed;
right: 20px;
line-height: 100px;
}
} .summary{
view{
padding: 5px;
}
.receive{
margin-top: 30px;
}
} // 右对齐
.right-fixed{
position: fixed;
right: 20px;
}
</style>

uniapp实现点击加载更多的更多相关文章

  1. tableView中的“点击加载更多”点击不到

    假设当前的tableView是_tableView,则可以这样设置 _tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0); 该属性用于设置当 ...

  2. android ListView的上部下拉刷新下部点击加载更多具体实现及拓展

    android ListView的上部下拉刷新下部点击加载更多具体实现及拓展 ListView下拉刷新,上拉自动加载更多 下拉刷新以及加载更多

  3. ajax点击加载更多数据图片(预加载)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. js点击加载更多可以增加几条数据的显示

      <div class="list"> <div class="one"> <div class="img" ...

  5. jQuery+php+Ajax文章列表点击加载更多功能

    jQuery+php+Ajax实现的一个简单实用的文章列表点击加载更多功能,点击加载更多按钮,文章列表加载更多数据,加载中有loading动画效果. js部分: <script type=&qu ...

  6. Vue——轻松实现vue底部点击加载更多

    前言 需求总是不断改变的,好吧,今天就把vue如何实现逐步加载更多和分布加载更多说下,默认你知道如何去请求数据的哈 一次请求 页面 使用slice来进行限制展现从0,a的数据 <div v-fo ...

  7. Spring+Hibernate+struts2+JPA 注解+跨域//完成手机端点击加载更多 下拉加载更多

    一.使用IDEA新建一个maven项目(student) 1.1.0编写pom文件,添加项目所需要的包 <?xml version="1.0" encoding=" ...

  8. PHP+Ajax点击加载更多列表数据实例

    一款简单实用的PHP+Ajax点击加载更多列表数据实例,实现原理:通过“更多”按钮向服务端发送Ajax请求,PHP根据分页参数查询将最新的几条记录,数据以JSON形式返回,前台Query解析JSON数 ...

  9. PHP+Ajax点击加载更多内容 -这个效果好,速度快,只能点击更多加载,不能滚动自动加载

    这个效果好,速度快,只能点击更多加载,不能滚动自动加载 一.HTML部分 <div id="more"> <div class="single_item ...

  10. Jquery点击加载更多

    一.点击加载更多有点像分页获取数据类似,下面是本人写的一个简单的小例子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...

随机推荐

  1. [转帖]JVM性能提升50%,聊一聊背后的秘密武器Alibaba Dragonwell

    https://zhuanlan.zhihu.com/p/453437019 今年四月五日,阿里云开放了新一代ECS实例的邀测[1],Alibaba Dragonwell也在新ECS上进行了极致的优化 ...

  2. [转帖]Jmeter_jmeter-plugins插件的安装使用

    一.安装JMter Plugins 1.官网下载 JMeter Plugins 的jar包 2. 将下载的jar包复制到 %JMETER_HOME%\lib\ext 目录下 3. 启动 JMeter ...

  3. [转帖]PostgreSQL(三) 内存参数优化和原理(work_mem)内存表 pgfincore插件使用方法

    1.常用内存参数 1.1 shared_buffers shared_buffers是PostgreSQL用于共享缓冲区的内存,是由8kb大小的块所形成的数组.PostgreSQL在进行更新.查询等操 ...

  4. ChatGPT学习之_shell脚本一例-查找版本冲突的第三方jar包

    ChatGPT学习之_shell脚本一例-查找版本冲突的第三方jar包 背景 自从换了Java后 产品里面用到了非常多的第三方组建,也就是很多jar包. 产品内的研发规范要求, jar包不能带版本号和 ...

  5. overflow的所有值,overlay不占位

    visible: 默认值.内容不会被修剪,会呈现在元素框之外. hidden: 内容会被修剪,并且其余内容是不可见的. scroll: 内容会被修剪,总是显示滚动条. auto: 内容被修剪,超出浏览 ...

  6. 【K哥爬虫普法】孤注一掷的爬虫er,究竟还要误入歧途多远?

    我国目前并未出台专门针对网络爬虫技术的法律规范,但在司法实践中,相关判决已屡见不鲜,K 哥特设了"K哥爬虫普法"专栏,本栏目通过对真实案例的分析,旨在提高广大爬虫工程师的法律意识, ...

  7. PHP伪协议与文件包含漏洞

    https://www.cnblogs.com/weak-chicken/p/12275806.html 1 file:// - 访问本地文件系统 2 http:// - 访问 HTTP(s) 网址 ...

  8. javaScript随机图片

    <script type="text/javascript"> //<!CDATA[ var pic = []; pic[0] = "链接"; ...

  9. 解锁ChatGLM-6B的潜力:优化大语言模型训练,突破任务困难与答案解析难题

    解锁ChatGLM-6B的潜力:优化大语言模型训练,突破任务困难与答案解析难题 LLM(Large Language Model)通常拥有大量的先验知识,使得其在许多自然语言处理任务上都有着不错的性能 ...

  10. 基于中文金融知识的 LLaMA 系微调模型的智能问答系统:LLaMA大模型训练微调推理等详细教学

    基于中文金融知识的 LLaMA 系微调模型的智能问答系统:LLaMA大模型训练微调推理等详细教学 基于 LLaMA 系基模型经过中文金融知识指令精调/指令微调(Instruct-tuning) 的微调 ...