v u e 3.0写下拉刷新

先要下载vue3.0,

在views里新建vue项目

先看效果图:

这是没上拉之前:

这是上拉了之后:

然后复制下面的代码:

<template>
    <div class="pulldown" ref="pulldown">
        <div class="pulldown-top"></div>
        <div class="pulldown-bottom"></div>
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
const pulldown = ref(null);
let disy = ref<number>(0);
let y = ref<number>(0);
// let disy = ref<number>(0)
const getPulldown = () => {
    return pulldown.value as unknown as HTMLDivElement;
};
const getChild = (n: number) => {
    return getPulldown().children[n] as HTMLDivElement;
};
onMounted(() => {
    getPulldown().ontouchstart = FnStart;
});
const FnStart = function (ev: TouchEvent) {
        getChild(0).style.transition = `null`
    disy.value = ev.changedTouches[0].pageY - y.value;
    getChild(1).ontouchmove = FnMove;
    getChild(1).ontouchend = FnEnd;
};
const FnMove = function (ev: TouchEvent) {
    y.value = ev.changedTouches[0].pageY - disy.value;
    getChild(0).style.height = y.value / 3 + "px";
};
const FnEnd = function (ev: TouchEvent) {
        getChild(0).style.transition = `0.4s ease height`


    console.log(y.value);
    if (y.value > 80) {
        y.value = 80;
        setTimeout(() => {
            y.value = 0;
            getChild(0).style.height = y.value + "px";
        }, 1000);
    } else {
        y.value = 0;
    }
    getChild(0).style.height = y.value + "px";
    getChild(1).ontouchmove = () => false;
    getChild(1).ontouchend = () => false;
};
</script>
<style lang="less" scoped>
.pulldown {
    .pulldown-top {
        width: 100vw;
        height: 0px;
        background-color: skyblue;
    }
    .pulldown-bottom {
        width: 100vw;
        height: 100vh;
        background-color:pink;
    }
}
</style>

记住写路由!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值