计时器停止器怎么与上面的秒表相应呢,按钮是显示出来了,但是不知道怎么建立响应,是要用到生命周期钩子吗?

html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Vue Mastery</title>
    <!-- Import Styles -->
    <link rel="stylesheet" href="./assets/styles.css" />
    <!-- Import Vue.js -->
    <script src="https://unpkg.com/[email protected]/dist/vue.global.js"></script>
  </head>
  <body>
    <div id="counter">
      Counter: {
    
    {
    
     counter }}
    </div>
    <button @click="stop timer">stop timer</button>

    <!-- Import Js -->
    <script src = "./main.js"></script>


    
  </body>
</html>

main.js

const Counter= {
    
    
  data() {
    
    
    return {
    
    
      counter: 0
    }
  },
  mounted() {
    
    
    setInterval(() => {
    
    
      this.counter++
    }, 1000)
  }
}
Vue.createApp(Counter).mount('#counter')

先放着?

猜你喜欢

转载自blog.csdn.net/weixin_40945354/article/details/114818916