Javascript 如何在 vue.js 中获取当前年份?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45757724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:12:18  来源:igfitidea点击:

How to get current year in vue.js?

javascriptvue.js

提问by Rifkan Razak

I want to display ?yearin my webpage.

我想?year在我的网页中显示。

How do I do the following in vue.js?

我如何在 vue.js 中执行以下操作?

document.write(new Date().getFullYear())

回答by choasia

Why not just use text interpolation?

为什么不直接使用文本插值

new Vue({
  el: '#app',
});
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>

<div id="app">
?{{ new Date().getFullYear() }}
</div>

回答by Sachin Dane

You can add current year automatically in your web page.

您可以在网页中自动添加当前年份。

<script>document.write(new Date().getFullYear())</script>

This will works for all browser's

这将适用于所有浏览器