npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cruda-element-plus

v1.5.1

Published

A Cruda adapter for element-plus

Downloads

21

Readme

cruda-element-plus

A Cruda adapter for element-plus.

Demo

Usage

1. Install

// Usually init cruda in main.js
import request from 'axios'
import CRUD from 'cruda-element-plus'
// set requester
createApp(App).use(CRUD, { request: request })

2. Activate

<script lang="ts" setup>
  import { useCrud } from 'cruda-element-plus'
  //通过useCrud函数获取$crud实例
  //对象方式激活时与element-ui行为一致
  const $crud = useCrud('/api/single')
  
  //Reload on mounted 
  onMounted(() => {
    $crud.reload()
  })
</script>

You can pass custom parameters to Cruda besides the URL when you activate it in object way

const $crud = useCrud({url:'/api/single',permission:'a_b_c'}) object way

then you can read it via params

this.$crud.params.permission

that's very useful if you want to do additional UI control like Auth

3. Multi-instance

<script lang="ts" setup>
  import { useCruds } from 'cruda-element-plus'
  const $cruds = useCruds({
    t1: '/api/single',
    t2: {
      url: '/api/multiple',
    },
  })

  //Reload instance 't1' on mounted 
  onMounted(() => {
    $cruds.t1.reload()
  })
</script>
<script lang="ts" setup>
  import { useCruds } from 'cruda-element-plus'
  const $cruds = useCruds({
    t1: {
      url:'/api/single',
      query:{type:'1'}
    },
    t2: {
      url: '/api/single',
      query:{type:'2'}
    },
  })

  //Reload instance 't1' with '?type=1' on mounted 
  onMounted(() => {
    //Same paramters will merged into query string
    $cruds.t1.reload({type:3})
  })
</script>

4. HOOK

<script lang="ts" setup>
  import CRUD, { onHook } from 'cruda-element-plus'

  const $crud = useCrud()

  onHook(CRUD.HOOK.AFTER_SUBMIT, (crud) => {
    ElNotification.success('提交成功')
    crud.toQuery()
  })
</script>

5. CRUD component

The first thing you create a CRUD component is to get $crud. Use lookUpCrud() to get that then you can do other business like do queries, toggle views and so on

<template>
  <el-table :data="$crud.table.data" @sort-change="(o) => $crud.changeSort(o)">
    <el-table-column prop="uname" label="uname" width="180" />
    <el-table-column prop="email" label="email" width="180" sortable="custom" />
    <el-table-column prop="ip" label="ip" />
    <el-table-column align="right">
      <template #default="{ row }">
        <el-button size="small" @click="$crud.toEdit(row)">Edit</el-button>
        <el-button size="small" type="danger" @click="toDelete(row)"
          >Delete</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
<script lang="ts" setup>
  import { lookUpCrud } from 'cruda-element-plus'
  // In element-plus, the lookUpCrud has only one optional argument `crudName`
  const $crud = lookUpCrud()

  function toDelete(row: Record<string, any>) {
    ElMessageBox.confirm('确认删除?').then(() => {
      $crud.toDelete(row)
    })
  }
</script>

6. URL params

Cruda supports URL param by :varName which makes you can build dynamic URLs. See below

<script lang="ts" setup>
  import { useCruds } from 'cruda-element-plus'
  const $cruds = useCruds({
    org: '/api/orgs',
    //param 'orgId' is used in 'user' instance
    user: '/api/orgs/:orgId/users'
  })

  //fill the param
  function setOrg(orgId){
    this.$cruds.user.setURLParams({orgId})
    this.$cruds.user.toQuery()
  }
</script>

Exportable

import CRUD,{...} from 'cruda-element-plus'
  • useCrud(restURL) : CRUD

    return a single instance

  • useCruds(restURLMap) : Record<string, CRUD>

    return a multi instance map

  • lookUpCrud(crudName?) : CRUD | null

    look up the nearest crud instance then return

  • onHook(hookName,hook) : void

    register a hook

Cruda

CRUD API please to Cruda