🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

viteser

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

viteser

允许直接在 vite .vue .tsx .ts 前端文件中写接口

latest
Source
npmnpm
Version
0.0.1-beta.36
Version published
Weekly downloads
6
-83.78%
Maintainers
1
Weekly downloads
 
Created
Source

把接口当作函数写在前端项目中

banner.png

[ENGLISH] [中文]

// src/api.ts
import { useEffect, useState } from 'react'
import { db } from './db'

// src/App.tsx
import { getUser } from './api'

export async function getUser(id: number) {
  'use server'
  return db.query(`SELECT * FROM users WHERE id = ${id}`)
}

function App() {
  const [user, setUser] = useState<{
    id: number
    name: string
  }>({ id: 0, name: '' })
  useEffect(() => {
    getUser(1).then(setUser)
  }, [])
  return <div>{user.name}</div>
}

🏃🏻‍♂️‍➡️ 开始

  • 安装 viteser 和其他依赖
npm install viteser
  • 修改 vite.config.ts
import { defineConfig } from 'vite'
import { ViteserPlugin } from 'viteser'

// https://vitejs.dev/config/
// noinspection JSUnusedGlobalSymbols
export default defineConfig({
  plugins: [
    ViteserPlugin(),
    // react() or vue() or other . . .
  ],
})

🔍 快速启动

https://github.com/sia-fl/viteser-demo

📦 最佳实践(长期维护)

https://github.com/sia-fl/buess

Keywords

use server api

FAQs

Package last updated on 16 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts