@braks/revue-draggable

中文文档
0.5.1发布于 2024/09/05MITTypeScriptESM + CJS近 30 天下载 9859

Revue Draggable

原始使用文档
文档目录8 节
  1. Table of Contents
  2. 🛠 Setup
  3. Using the components
  4. 🔌 Registering Revue Draggable
  5. 🎮 Quickstart
  6. 🧪 Development
  7. 🐛 Debugging
  8. 🕵🏻‍♂️ Tests

Revue Draggable

top-language dependencies Status devDependencies Status vulnerabilities GitHub code size in bytes GitHub last commit

Make your Vue components draggable. 🤏

Supports Vue 2 and Vue 3! Comes with a 🔋 batteries included component / directive / composable or for users who want more control a simple abstraction over drag events with the core, wich is also available as a component / directive / composable.

Based on React Draggable.

Check the Docs 📔 for an in-depth explanation and the Demo 🪄 to see Revue Draggable in action.

Table of Contents

🛠 Setup

$ npm i --save @braks/revue-draggable

# or
$ yarn add @braks/revue-draggable

# or
$ pnpm add @braks/revue-draggable

For Vue2 add the composition-api to your dependencies (if you're using Vue < 2.7).

$ yarn add @braks/revue-draggable @vue/composition-api

# or
$ npm i --save @braks/revue-draggable @vue/composition-api

Using the components

Webpack (Vue2)

// webpack.config.js

resolve: {
    alias: {
        vue: 'vue/dist/vue.js'
    }
}

Nuxt

// nuxt.config.ts
export default {
    alias: {
        vue: 'vue/dist/vue.js'
    }
}

🔌 Registering Revue Draggable

// Vue3
import { createApp } from 'vue';
import Draggable, { DraggablePlugin, DraggableDirective } from '@braks/revue-draggable';

const app = createApp();

// Use as Plugin (registers directives and components)
app.use(DraggablePlugin);

// or
app.directive('draggable', DraggableDirective)
app.component('Draggable', Draggable);

app.mount('#root');
// Vue2 
import Vue from 'vue';
import { DraggablePlugin, DraggableDirective } from '@braks/revue-draggable';

// Use as Plugin
Vue.use(DraggablePlugin)

// or
Vue.directive('draggable', DraggableDirective)
Vue.component('Draggable', Draggable)

🎮 Quickstart

The easiest way to make your elements draggable is by using the DraggableDirective which will handle everything for you with no configuration necessary.

<div v-draggable="/* Pass DraggableProps as binding value here */" class="box">I use a directive to make myself draggable</div>

Or use the component wrapper. (In Vue2 make sure to include the full-build, runtime-build only works for Vue3.)

<Draggable>
  <div class="box">I use a wrapper</div>
</Draggable>

Check the example file for more in-detail examples like dropping elements, setting boundaries or syncing states.

🧪 Development

This project uses Vite for development and Rollup to create a distribution.

# start (dev)
$ pnpm dev

# build app
$ pnpm build

# serve app from build
$ pnpm serve

# build dist
$ pnpm build:dist

🐛 Debugging

Set the environment variable DRAGGABLE_DEBUG to enable logs on drag handlers.

🕵🏻‍♂️ Tests

Testing is done with Cypress. You can find the specs in the cypress directory;

$ pnpm ci # starts test server and runs tests, make sure port 3000 is open

版本与发布记录

@braks/revue-draggable 共发布 61 个版本,首次发布于 2021/07/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.5.1latest2024/09/052 年前
0.5.02024/03/112 年前
0.4.32023/01/113 年前
0.4.22022/02/064 年前
0.4.12021/12/074 年前
0.4.02021/12/074 年前

其他发布通道:next → 0.3.0-5。

关于 @braks/revue-draggable 的常见问题

如何安装 @braks/revue-draggable?

在项目目录运行 npm install @braks/revue-draggable,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^2.0.0 || >=3.0.5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@braks/revue-draggable 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@braks/revue-draggable 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@braks/revue-draggable 可以商用吗?

@braks/revue-draggable 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@braks/revue-draggable 的下载量有多少?

根据 npm 官方下载统计,@braks/revue-draggable 在 2026/10/09 – 2026/11/07 这 30 天内被下载 9,859 次,日均约 329 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@braks/revue-draggable 还在维护吗?

最新版本 0.5.1 发布于 2024/09/05(2 年前);至今共发布 61 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/07/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。