Kuu front-end tools
npm i kuu-tools
import { get } from 'kuu-tools'
const data = await get('/member/get?foo=1&bar=2')
import { post } from 'kuu-tools'
const data = await post('/member/signup', { user: 'foo', name: 'bar' })
import { put } from 'kuu-tools'
const data = await put('/member/signup?foo=1&bar=2', { user: 'foo', name: 'bar' })
import { del } from 'kuu-tools'
const data = await del('/member/signup?foo=1&bar=2', { user: 'foo', name: 'bar' })
import { create } from 'kuu-tools'
// create a role
const data = await create('Role', { Code: 'foo', Name: 'bar' })
// batch create roles
const data = await create('Role', [{ Code: 'foo1', Name: 'bar1' }, { Code: 'foo2', Name: 'bar2' }])
import { update } from 'kuu-tools'
// update a param
const data = await update('param', { ID: 5 }, { Value: 'new value', Name: 'foobar' })
// batch updates
const data = await update('param', { ID: { $in: [5, 10, 11] } }, { Value: 'new value' }, true)
import { remove } from 'kuu-tools'
// delete a param
const data = await remove('param', { ID: 5 })
// batch delete
const data = await remove('param', { ID: { $in: [5, 10, 11] } }, true)
// batch and unsoft delete
const data = await remove('param', { ID: { $in: [5, 10, 11] } }, true, true)
import { list, one, id } from 'kuu-tools'
// list query
const data = await list('param', { cond: { ID: { $in: [5, 10, 11] } }, page: 3, sort: '-CreatedAt' })
// query only one record
const data = await one('param', { cond: { Name: 'foo' } })
// query by id
const data = await id('param', 11)
{
"hello": "你好",
"welcome": "欢迎 {{name}}"
}
import { withLocale } from 'kuu-tools'
class Param extends React.Component {
render () {
return (
<div>
<div>{this.props.L('hello', 'Hello')}</div> /* => 你好 */
<div>{this.props.L('not_found', 'Not found')}</div> /* => Not found */
<div>{this.props.L('welcome', 'Welcome Kuu', { name: 'Kuu' }}</div> /* => 欢迎 Kuu */
</div>
)
}
}
export default withLocale(Param)
Notes:
-
this.props.L
can only be used inrender
, otherwise it will not respond to language updates in real time. withLocale(Param)
withLocale(withRouter(Param))
withLocale(connect(mapStateToProps)(withRouter(Param)))
Message supports the mustache syntax.