baseresponse
v1.0.2
Published
class response.
Downloads
5
Readme
baseresponse
class response
示例
const Response = require('baseresponse')
const result = new Response(200, 1, '成功', {a:10}) // Response {status: 200, success: 1, message: '成功', data: {a:10} }
const Response = require('baseresponse')
const result = Response.SUCCESS
console.log(result) // Response {status: 200, success: 1, message: '成功', data: {} }
const Response = require('baseresponse')
Response.success.setData({a: 10})
const result = Response.success
console.log(result) // Response {status: 200, success: 1, message: '成功', data: { a: 10 } }
const Response = require('baseresponse')
Response.success.setStatus(304)
Response.success.setData({a: 10})
const result = Response.success
console.log(result) // Response { status: 304, success: 1, message: '成功', data: { a: 10 } }
- ES6
import Response from 'baseresponse'
const result = new Response(200, 1, '成功', {a:10}) // Response {status: 200, success: 1, message: '成功', data: {a:10} }
import Response from 'baseresponse'
const result = Response.SUCCESS
console.log(result) // Response {status: 200, success: 1, message: '成功', data: {} }
import Response from 'baseresponse'
Response.success.setData({a: 10})
const result = Response.success
console.log(result) // Response {status: 200, success: 1, message: '成功', data: { a: 10 } }
import Response from 'baseresponse'
Response.success.setStatus(304)
Response.success.setData({a: 10})
const result = Response.success
console.log(result) // Response { status: 304, success: 1, message: '成功', data: { a: 10 } }