2017-06-20 59 views
1

不知道我在哪里错了,但我试图在Vue.js组件中输出当前日期。但不是返回一个日期字符串(即2017/02/02),而是返回一个对象字符串(??)。输了...Vue.js&Moment.js输出日期重做对象而不是日期字符串

<template> 
    <div> 
     <input type="text" :value="initialDate"> 
    </div> 
</template> 

<script> 

    export default { 
     props: ['date', 'user'], 

     computed: { 
      initialDate() { 
       return this.date ? this.date : this.fetchCurrentDate 
      } 
     }, 

     methods: { 
      fetchCurrentDate() { 
       return window.moment() 
      }, 
     } 
    } 
</script> 

在浏览器中,我看到这个作为输入值:

function boundFn(a) { var l = arguments.length; return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx) } 

当它应该是一个实际日期字符串。

回答

1

您需要致电fetchCurrentDate功能。不参考它。

initialDate() { 
     return this.date ? this.date : this.fetchCurrentDate() 
} 
+0

该死的。 FML ...总是那些小东西。感谢您的帮助:) #TimeForBreak –

+2

@MikeBarwick在那里:) – Bert

相关问题