🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ### get() 获取器,查询数据时触发 ~~~ 'use strict'; const moment = require('moment') module.exports = app => { const { STRING, INTEGER, DATE } = app.Sequelize; const User = app.model.define('users', { id: { type: INTEGER(20).UNSIGNED, primaryKey: true, autoIncrement: true }, gender: { type: ENUM, values: ['男','女','保密'], allowNull: true, defaultValue: '男', comment: '用户性别'}, // 查询数据时,格式化时间 createdAt: {type: DATE, get() {return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm:ss')}}, updatedAt: {type: DATE, get() {return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm:ss')}} }); return User; }; ~~~