npm init -y
npm i @vant/weapp -S --production
"packNpmManually":true,
"packNpmRelationList":[
{
"packageJsonPath":"./package.json",
"miniprogramNpmDistDir":"./"
}
]
"usingComponents":{
"van-count-down":"@vant/weapp/van-count-down/index"
}
<van-count-down></van-count-down>
wxml文件
<navBar
titleName="countdown组件实现倒计时"
showLeftArrow="{{false}}"
/>
<view class="head">
<image class="img" src="../../image/countdown2.png"></image>
<van-count-down use-slot
time="{{minusRes}}"
bind:change="onchange"
>
<text class="item">{{timeData.minutes}}</text>
<text class="item">:</text>
<text class="item">{{timeData.seconds}}</text>
</van-count-down>
</view>
js文件
Page({
data: {
minusRes:, //按照项目需求自行计算
timeData:{}
},
onchange(e){
this.setData({
timeData:e.detail
})
}
})
wxss文件
.middle{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 20rpx;
background-color: rgb(246,246,246);
border-radius: 30rpx;
height: 180px;
}
.img{
width: 140rpx;
height: 80px;
animation: rote 2s infinite;
display: block;
margin-bottom: 20px;
}
.item{
color: #000000;
font-size: 60rpx;
font-weight: 700;
}
/* 定义动画,使其旋转 */
@keyframes rote {
form {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
count-down组件实现倒计时