我的api包括名称和日期数据
名称类型为字符串。日期类型为字符串
此外,在这个项目中包括最新版本的 Vue.js
postTodo(){
axios({
method: 'post',
url: 'my-api',
headers : {
token: this.token
},
data: {
name : "Hello",
// it's not working => JSON.stringify(new Date())
date : JSON.stringify(new Date())
}
}).catch(err => console.log(err))
.then( response =>
console.log(response))
}
这是一个用于检查发布请求的按钮
<button @click="postTodo">Send To-Do</button>
所以,我想从日期对象转换为字符串。如何解决这个问题?
答案 0 :(得分:0)
我解决了这个问题。像这样:
let dates= new Date()
let month = dates.getUTCMonth() + 1
let day = dates.getUTCDate()
let year = dates.getUTCFullYear()
let currentDate = year + "-" + month + "-" + day
答案 1 :(得分:-1)