2-5计算属性

来源:2-5 Vue中的计算属性和侦听器

慕木暮目

2020-09-20 15:25

使用计算属性实现日期的格式化,只显示年月日

这个要怎么弄呢?

求大神帮忙。。。

写回答 关注

2回答

  • 宝求cross
    2020-09-21 20:49:27
    已采纳
    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><script src="./vue.js"></script></head><body><div id="app"></div><script>new Vue({el: "#app",template: "<h1>{{fullDate}}</h1>",computed: {fullDate: function () {let now = new Date();let year = now.getFullYear();let month = now.getMonth();let date = now.getDate();return `${year}-${month}-${date}`; //根据自己的需要拼接字符串},},});</script></body></html>


    慕木暮目

    真乃大神也!

    2020-09-22 20:52:13

    共 1 条回复 >

  • Imthen
    2021-01-03 21:49:16

    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><script src="./vue.js"></script></head><body><div id="app"></div><script>new Vue({el: "#app",template: "<h1>{{fullDate}}</h1>",computed: {fullDate: function () {let now = new Date();let year = now.getFullYear();let month = now.getMonth();let date = now.getDate();return `${year}-${month}-${date}`; //根据自己的需要拼接字符串},},});</script></body></html>

    01

vue2.5入门

快速理解Vue编程理念上手Vue2.0开发。

146230 学习 · 657 问题

查看课程

相似问题