learning target:
学习目标如下:
For example:
- The use of the progress loading progress bar in uniapp displays the progress bar of data loading on the page to make the user experience better
Learning Content:
学习内容如下所示:
-
Description of relevant properties
-
display of progress bar
<view v-show="progressVisible" class="progress-box">
<progress :percent="percent" show-info stroke-width="4" />
</view>
- Whether to display the control of the attribute
progressVisible: false,
- show progress bar
that.progressVisible = true
- Styling the progress bar
.progress-box {
display: flex;
height: 50rpx;
margin-bottom: 60rpx;
}
Knowledge summary:
提示:这里统计学习计划的总量
- 1. The display of the progress bar and the setting of related properties
<view class="progress-box">
<progress
:percent="percent" //百分比
show-info //在进度条右侧显示百分比
active="true" //进度条从左往右的动画
active-mode="forwards" //动画从上次结束点接着播
:stroke-width="3" //进度条线的宽度,单位为 px
backgroundColor="#F5F5F5" //未选择的进度条的颜色
/>
</view>
- 2. Define relevant variables
data() {
return {
percent:0 //百分比0~100
}
},
- 3. The method of calling
methods: {
change(){
// 开启定时器,定时器同样可以用在请求当中
let clearInt = setInterval(()=>{
this.percent ++;
if(this.percent === 100){
clearInterval(clearInt)
uni.showToast({
title: "加载成功",
con: "success"
});
}
},30)
}
}
-
4. Just call the method directly. If you want to call the method automatically when you enter the page, you can call the method directly in onLoad.
onLoad() { this.change() }
-
Style settings
.progress-box {
display: flex;
height: 50rpx;
margin-bottom: 60rpx;
}