Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/holyhigh2/cruda-compelem
A Cruda adapter for compelem
https://github.com/holyhigh2/cruda-compelem
Last synced: 8 days ago
JSON representation
A Cruda adapter for compelem
- Host: GitHub
- URL: https://github.com/holyhigh2/cruda-compelem
- Owner: holyhigh2
- License: mit
- Created: 2024-11-02T14:23:25.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-02T14:46:53.000Z (about 2 months ago)
- Last Synced: 2024-12-02T20:49:50.053Z (25 days ago)
- Language: TypeScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# cruda-compelem
A Cruda adapter for compelem.
## Usage
### 1. Install
```js
// Usually init cruda in main.js
import request from "axios";
import CRUD from "cruda-compelem";
// set requester
CRUD.request = request;
```### 2. Activate
```ts
class Xx extends CompElem {
...
@crud("/api/single")
crud: CRUD;
...
}
```You can pass custom parameters to Cruda besides the URL when you activate it in object form. Such as below
```ts
class Xx extends CompElem {
...
@crud({ url: "auth/users", permission: "a_b_c" })
crud: CRUD;
...
}
```then you can read it via `params`
```js
this.crud.params.permission;
```### 3. Multi-instance
```ts
class Xx extends CompElem {
...
@crud("/api/single")
crud: CRUD;@crud("/api/multiple")
crud2: CRUD;
...
}
```### 4. HOOKs
```ts
class Xx extends CompElem {
...
@crud("/api/single")
crud: CRUD;
...constructor() {
super();
//也可以写在其他生命周期钩子中
onHook(this, CRUD.HOOK.BEFORE_QUERY, (c: CRUD, rs) => {
console.log(rs, 'onHook')
})
}
}
```### 5. CRUD component
```ts
class Xx extends CompElem {
crud: CRUD;
mounted() {
this.crud = lookUpCrud(this, "crud2");
}
}
```### 6. URL params
Same as others
## Exportable
```js
import CRUD,{...} from 'cruda-compelem'
```- CRUD
> crud namespace, can bind global defaults, hooks
- lookUpCrud(vm, crudName?) : CRUD | null
> look up the nearest crud instance then return
- onHook(vm,hookName,hook) : ()=>void
> add an extra hook## Cruda
CRUD API please to [Cruda](https://github.com/holyhigh2/cruda)