我正在使用Bootastrap-Vue与JavaScript结合使用,我想在我的代码中使用Moment.js。
我有时间,但不正确......有人可以帮助我吗?
顺便说一下,这是我在StackOverflow的第一个问题,所以如果我误解了,我会道歉。
谢谢。
var moment = require('moment')
export default {
name: 'something',
data() {
return {
something: [],
currentPage: 1,
total_something: 1,
something_fields: {
id: {
label: 'Id',
sortable: true
},
purpose: {
label: 'Purpose',
sortable: false
},
state: {
label: 'State',
sortable: false
},
updated: {
key: 'updated',
label: 'Updated',
formatter: (value, key, item) => {
return moment(item.updated).calendar();
}
}
},
}
},
created() {
this.loadSomething(0, 10)
},
watch: {
currentPage: function (newPage) {
this.loadSomething(newPage, 10)
}
}, methods: {
loadSomethings(currentPage, limit) {
if (!(Number.isInteger(currentPage) && Number.isInteger(limit))) {
currentPage = 0
limit = 10
}
var offset = (currentPage - 1) * limit
window.API.get('something?offset=' + offset + '&limit=' + limit)
.then(response => {
this.something = response.data.something;
this.total_something s = response.data.total;
console.log(response.data.something)
})
.catch(e => {
this.errors.push(e)
})
}
}
}
答案 0 :(得分:1)
使用它:
Minute, Hour, Da_of_Week(1-7, 1=Sun), Day_of_Month(1-31), Day_of_Year(1-365), Week (1-52), Month (1-12)
答案 1 :(得分:1)
formatter: (value, key, item) => {
if(item.updated) {
return moment(item.updated).format(); // format(YOUR DATE FORMAT)
}
}