VUE Element UI 60秒倒计时

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
	</head>

	<body>
		<el-container id='app'>
			<el-button @click="sendMsg" type="primary" :disabled="isDisabled">{{buttonName}}</el-button>
			</el-table>
		</el-container>
	</body>
	<!-- 先引入 Vue -->
	<script src="https://unpkg.com/vue/dist/vue.js"></script>
	<!-- 引入组件库 -->
	<script src="https://unpkg.com/element-ui/lib/index.js"></script>
	<script>
		new Vue({
			el: '#app',
			data: {
				buttonName: "发送短信",
				isDisabled: false,
				time: 10
			},
			methods: {
				sendMsg() {
					let me = this;
					me.isDisabled = true;
					let interval = window.setInterval(function() {
						me.buttonName = '(' + me.time + '秒)后重新发送';
						--me.time;
						if(me.time < 0) {
							me.buttonName = "重新发送";
							me.time = 10;
							me.isDisabled = false;
							window.clearInterval(interval);
						}
					}, 1000);

				}

			}

		})
	</script>

</html>

展开阅读全文

没有更多推荐了,返回首页