很简单,不做过多解释了,直接上代码

完整代码

<script>
    data() {
        return {
            startTime: 0,
            intervalId: null,
        }
    }
    methods: {
        startCall() {
            this.startTime = Date.now();
            this.intervalId = setInterval(() => {
	            this.updateDuration();
	        }, 1000);
        },
			
        updateDuration() {
            let elapsed = Date.now() - this.startTime; // 已经过的毫秒数
            let hours = Math.floor(elapsed / 3600000);
            let minutes = Math.floor((elapsed % 3600000) / 60000);
            let seconds = Math.floor((elapsed % 60000) / 1000);
	 
	        // 补零操作
            hours = hours < 10 ? '0' + hours : hours;
	        minutes = minutes < 10 ? '0' + minutes : minutes;
	        seconds = seconds < 10 ? '0' + seconds : seconds;
	 
            this.dialTimeText = hours + ':' + minutes + ':' + seconds;
        },
			
        endCall() {
	        clearInterval(this.intervalId);
        }
    }
</script>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.