nuxt.js - 如何在创建计时器中使用 setInterval
问题描述
我在这样的页面中有一个计时器。
<h5 class="pa-2 text-center">{{ timestamp }}</h5>
初始timestamp: '',
数据,我有一个设置时间戳的功能。
方法中的功能
getNow() {
const today = new Date();
const date1 = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
const time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
const dateTime = date1 + " " + time;
this.timestamp = dateTime;
}
并在mounted中使用此功能。
setInterval(() => this.getNow() , 1000);
我每秒有 2 个错误。错误: [Vue 警告]:属性或方法“日期”未在实例上定义,但在渲染期间被引用。通过初始化该属性,确保该属性是反应性的,无论是在数据选项中,还是对于基于类的组件。
解决方案
推荐阅读
- c# - 在 Asp.net Core 中使用 JQuery 重定向页面
- python - TypeError:“LogisticRegression”对象不可调用
- php - 在 mysqli 中不能使用这个 mysqli_fetch_field_direct 函数
- asp.net-web-api - 为 azure CDN 清除创建 ASP.net Web api
- opencv - 旋转打包的 YUV 视频帧的有效方法?
- python - 如何在没有 .kv 文件的情况下在 kivy 中使用屏幕管理器的按钮行为
- r - 尝试编写 plyr::ldply 的 dplyr 版本
- javascript - 希望 webpack 输出到单独的 .css 文件而不是合并为一个
- javascript - JavaScript QuillJS - 获取和设置内容
- spring-boot - 带有 oauth2 的 Spring Security 5 导致“principalName 不能为空”错误