40 Star 272 Fork 4

jry/uview-plus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
code.nvue 3.91 KB
一键复制 编辑 原始数据 按行查看 历史
<template>
<view class="u-page">
<view class="u-demo-block">
<text class="u-demo-block__title">基础功能</text>
<view class="u-demo-block__content">
<up-code
ref="uCode"
@change="codeChange"
seconds="20"
change-text="XS获取"
@start="disabled1 = true"
@end="disabled1 = false"
></up-code>
<up-button
@tap="getCode"
:text="tips"
type="success"
size="small"
:disabled="disabled1"
></up-button>
</view>
</view>
<view class="u-demo-block">
<text class="u-demo-block__title">保持倒计时(开始后,左上角返退出此页面再进入,会发现倒计时还在继续)</text>
<view class="u-demo-block__content">
<up-code
ref="uCode1"
@change="codeChange1"
keep-running
change-text="倒计时XS"
@start="disabled2 = true"
@end="disabled2 = false"
></up-code>
<up-button
type="primary"
@tap="getCode1"
:text="tips1"
size="small"
:disabled="disabled2"
></up-button>
</view>
</view>
<view class="u-demo-block">
<text class="u-demo-block__title">文本样式</text>
<view class="u-demo-block__content">
<up-code
ref="uCode2"
@change="codeChange2"
keep-running
start-text="点我获取验证码"
></up-code>
<text
@tap="getCode2"
:text="tips2"
class="u-page__code-text"
>{{tips2}}</text>
</view>
</view>
</view>
</template>
<script>
import { toast } from '@/uni_modules/uview-plus'
export default {
data() {
return {
tips: '',
// 此为错误定义,见下方说明
// refCode: null,
tips1: '',
tips2: '',
disabled1: false,
disabled2: false,
disabled3: false
}
},
onReady() {
// 注意这里不能将一个组件赋值给data的一个变量,否则在微信小程序会
// 造成循环引用而报错,如果你想这样做,请在onReady或者onLoad生命周期中定义,如下
// this.refCode = this.$refs.uCode;
},
methods: {
codeChange(text) {
this.tips = text;
},
codeChange1(text) {
this.tips1 = text;
},
codeChange2(text) {
this.tips2 = text;
},
getCode() {
if (this.$refs.uCode.canGetCode) {
// 模拟向后端请求验证码
uni.showLoading({
title: '正在获取验证码'
})
setTimeout(() => {
uni.hideLoading();
// 这里此提示会被this.start()方法中的提示覆盖
toast('验证码已发送');
// 通知验证码组件内部开始倒计时
this.$refs.uCode.start();
}, 2000);
} else {
toast('倒计时结束后再发送');
}
},
getCode1() {
if (this.$refs.uCode1.canGetCode) {
// 模拟向后端请求验证码
uni.showLoading({
title: '正在获取验证码'
})
setTimeout(() => {
uni.hideLoading();
// 这里此提示会被this.start()方法中的提示覆盖
toast('验证码已发送');
// 通知验证码组件内部开始倒计时
this.$refs.uCode1.start();
}, 2000);
} else {
toast('倒计时结束后再发送');
}
},
getCode2() {
if (this.$refs.uCode2.canGetCode) {
// 模拟向后端请求验证码
uni.showLoading({
title: '正在获取验证码'
})
setTimeout(() => {
uni.hideLoading();
// 这里此提示会被this.start()方法中的提示覆盖
toast('验证码已发送');
// 通知验证码组件内部开始倒计时
this.$refs.uCode2.start();
}, 2000);
} else {
toast('倒计时结束后再发送');
}
}
}
}
</script>
<style lang="scss">
.u-page {
&__code-text {
color: $u-primary;
font-size: 15px;
}
}
.u-demo-block__content {
@include flex;
}
</style>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jry/uview-plus.git
git@gitee.com:jry/uview-plus.git
jry
uview-plus
uview-plus
3.x

搜索帮助