我怎样才能在 属性 时间内获得现在的小时数?
How can I get the hours for now in a time property?
我怎样才能在 VueCLI 中获取时间 属性 消息列表的时间?当我点击按钮时,这个 属性 现在被填充为时间。时间 属性 将是小数部分。示例:(23.14)
有数据:
messagesList : [
{
id : 1,
content : "Benim mesajım",
opposite : false,
me : true,
time : 23.13,
},
{
id : 2,
content : "Karşı tarafın mesajı",
opposite : true,
me : false,
time : 23.13,
}
],
代码在那里:
this.messagesList.push(
{
id : this.messagesList.length + 1,
content : this.inputText,
opposite : false,
me : true,
time : ?,
}
只需创建一个函数以return您想要的格式的当前时间,并在添加消息时调用它。
函数如下:
function getTime() {
return parseFloat(`${new Date().getHours()}.${new Date().getMinutes()}`)
}
这里是消息列表的推送:
this.messagesList.push({
id: this.messagesList.length + 1,
content: this.inputText,
opposite: false,
me: true,
time : getTime(),
}
我怎样才能在 VueCLI 中获取时间 属性 消息列表的时间?当我点击按钮时,这个 属性 现在被填充为时间。时间 属性 将是小数部分。示例:(23.14)
有数据:
messagesList : [
{
id : 1,
content : "Benim mesajım",
opposite : false,
me : true,
time : 23.13,
},
{
id : 2,
content : "Karşı tarafın mesajı",
opposite : true,
me : false,
time : 23.13,
}
],
代码在那里:
this.messagesList.push(
{
id : this.messagesList.length + 1,
content : this.inputText,
opposite : false,
me : true,
time : ?,
}
只需创建一个函数以return您想要的格式的当前时间,并在添加消息时调用它。
函数如下:
function getTime() {
return parseFloat(`${new Date().getHours()}.${new Date().getMinutes()}`)
}
这里是消息列表的推送:
this.messagesList.push({
id: this.messagesList.length + 1,
content: this.inputText,
opposite: false,
me: true,
time : getTime(),
}