html↓
<template><view><button @click="start">开始</button><button @click="end">结束</button>{{nums}}</view></template>
data↓
data() {return {nums:"00:00:00",timer:''}},
methods↓
methods: {start() {var hour, minute, second; /*时 分 秒*/hour = minute = second = 0; //初始化var millisecond = 0; //毫秒this.timer = setInterval(() => {millisecond = millisecond + 50;// console.log("---millisecond----"+millisecond);if (millisecond >= 1000) {millisecond = 0;second = Number.parseInt(second) + 1;}if (second >= 60) {second = 0;minute = Number.parseInt(minute) + 1;}if (minute >= 60) {minute = 0;hour = Number.parseInt(hour) + 1;}// console.log("-------"+hour+'时'+minute+'分'+second+'秒');if (hour < 10) {hour = Number.parseInt(hour)hour = '0' + hour}if (minute < 10) {minute = Number.parseInt(minute)minute = '0' + minute}if (second < 10) {second = Number.parseInt(second)second = '0' + second}this.nums = hour + ':' + minute + ':' + second;}, 50);},end() {clearInterval(this.timer);}}