Coder Social home page Coder Social logo

dtd-vue's Introduction

DTD-Vue 是一个基于数据协议的,适合低代码配置的拖拽vue组件

主要特点:

  • 轻量,使用简单
  • 自定义程度高

使用:

  1. 全局引入
import App from './App.vue'
import DragToDrop from 'dtd-vue'

const app = createApp(App)
app.use(DragToDrop)
app.mount('#app')

  1. 按需引入
import { DtdPod } from 'dtd-vue'
import { DragToDrop } from 'dtd-vue'

使用案例

<script setup lang="ts">
import { ref } from 'vue'

const data = ref([
  {
    id: 12,
    name: 'Input',
  },
  {
    id: 13,
    name: 'Button',
  },
  {
    id: 14,
    name: 'Card',
    droppable: true,
    children: [
      {
        id: 15,
        name: 'CardHeader',
      },
      {
        id: 16,
        name: 'CardBody',
      },
      {
        id: 17,
        name: 'CardFooter',
      },
    ],
  }
])
</script>

<template>
  <div style="padding: 24px;">
    <dtd-pod>
        <div>
          <DragToDrop nodeClass="node-class" class="dtd-root" v-model="data">
              <template #default="{ item }">
                  <div class="dtd-item">{{ item.props?.name }}</div>
              </template>
          </DragToDrop>
        </div>
      <template #ghost="{ item }">
        <div class="ghost-custom">{{ item?.name }}</div>
      </template>
    </dtd-pod>
  </div>
  
  <div class="title">渲染数据:</div>
  <div class="code">
    <pre>{{ data }}</pre>
  </div>
</template>

样式参考:

html,body,#app {
    height: 100%;
    margin: 0;
}

.title {
    font-size: 1.2em;
    padding: 0 20px;
}

pre {
    margin: 0;
}

.container {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 20px;
}
.left, .right {
    flex: 1;
}
.ghost-custom {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    padding: 5px;
    border-radius: 5px;
}

.node-class {
    flex: 1;
    background-color: #f0f0f0;
    padding: 10px;
    /* border: 1px solid #0ac385; */
}

.dtd-root {
    background-color: #ececec;
    padding: 4px;
}

.flex {
    display: flex;
    gap: 10px;
}

.dtd-item {
    padding: 10px;
    background-color: white;
}

.code {
    background-color: #f0f0f0;
    padding: 10px;
}

效果:

alt text

dtd-vue's People

Contributors

orangespatial avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.