当前位置:首页 > VUE

vue实现看板

2026-01-07 20:27:44VUE

Vue 实现看板功能

使用 Vue 实现看板功能可以通过组件化开发、状态管理和拖拽库结合完成。以下是一个完整的实现方案:

基础项目结构

src/
├── components/
│   ├── KanbanBoard.vue      # 看板容器
│   ├── KanbanColumn.vue     # 看板列
│   └── KanbanCard.vue       # 看板卡片
├── store/                   # 状态管理
│   └── index.js             
└── App.vue

状态管理(Vuex)

// store/index.js
export default new Vuex.Store({
  state: {
    columns: [
      {
        id: 1,
        title: "待处理",
        cards: [
          { id: 1, content: "任务1" },
          { id: 2, content: "任务2" }
        ]
      },
      {
        id: 2,
        title: "进行中",
        cards: []
      }
    ]
  },
  mutations: {
    MOVE_CARD(state, { fromColumn, toColumn, cardIndex }) {
      const card = state.columns[fromColumn].cards.splice(cardIndex, 1)[0]
      state.columns[toColumn].cards.push(card)
    }
  }
})

拖拽功能实现

安装拖拽库:

npm install vuedraggable
<!-- KanbanColumn.vue -->
<template>
  <div class="column">
    <h3>{{ column.title }}</h3>
    <draggable 
      v-model="column.cards"
      group="cards"
      @end="onDragEnd"
    >
      <KanbanCard 
        v-for="card in column.cards"
        :key="card.id"
        :card="card"
      />
    </draggable>
  </div>
</template>

<script>
import draggable from 'vuedraggable'
export default {
  props: ['column'],
  components: { draggable },
  methods: {
    onDragEnd(event) {
      this.$emit('card-moved', {
        fromIndex: event.oldIndex,
        toIndex: event.newIndex
      })
    }
  }
}
</script>

看板主组件

<!-- KanbanBoard.vue -->
<template>
  <div class="kanban-board">
    <KanbanColumn
      v-for="(column, index) in columns"
      :key="column.id"
      :column="column"
      @card-moved="handleCardMove(index, $event)"
    />
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  computed: {
    ...mapState(['columns'])
  },
  methods: {
    handleCardMove(columnIndex, event) {
      this.$store.commit('MOVE_CARD', {
        fromColumn: columnIndex,
        toColumn: event.newIndex >= 0 ? columnIndex : null,
        cardIndex: event.fromIndex
      })
    }
  }
}
</script>

<style scoped>
.kanban-board {
  display: flex;
  gap: 20px;
  padding: 20px;
}
.column {
  background: #f0f0f0;
  padding: 15px;
  border-radius: 5px;
  min-width: 250px;
}
</style>

卡片组件

<!-- KanbanCard.vue -->
<template>
  <div class="card">
    {{ card.content }}
  </div>
</template>

<script>
export default {
  props: ['card']
}
</script>

<style scoped>
.card {
  background: white;
  padding: 10px;
  margin: 5px 0;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
</style>

功能扩展建议

  1. 持久化存储
    添加 localStorage 或 IndexedDB 支持保存看板状态

  2. API 集成
    通过 axios 连接后端 API 实现数据同步

  3. 卡片详情
    添加点击卡片显示详细信息的模态框功能

  4. 多用户协作
    集成 WebSocket 实现实时协作更新

  5. 筛选排序
    在列头添加筛选和排序功能按钮

    vue实现看板

这个实现方案使用了 Vue 的响应式特性配合 Vuex 进行状态管理,通过 vuedraggable 实现拖拽功能,组件结构清晰易于扩展。根据实际需求可以调整样式和交互细节。

标签: 看板vue
分享给朋友:

相关文章

vue实现switch

vue实现switch

Vue 实现 Switch 开关组件 在 Vue 中实现 Switch 开关组件可以通过自定义组件或使用现有 UI 库完成。以下是几种常见实现方式: 自定义 Switch 组件 创建一个基础 Sw…

vue实现表白

vue实现表白

Vue 实现表白页面 使用 Vue 可以快速创建一个动态、交互式的表白页面。以下是一个简单的实现方案: 基础结构 创建一个 Vue 项目或单文件组件,包含以下核心部分: <template&…

vue轮询实现

vue轮询实现

Vue 轮询实现方法 在 Vue 中实现轮询可以通过以下几种方式: 使用 setInterval data() { return { pollInterval: null }…

vue广播实现

vue广播实现

vue广播实现 在Vue中实现广播功能可以通过事件总线(Event Bus)或Vuex来完成。以下是两种常见的实现方式: 使用事件总线(Event Bus) 事件总线是一种简单的跨组件通信方式,适用…

vue实现联动

vue实现联动

Vue 实现联动效果 联动效果通常指多个组件或表单元素之间相互影响,例如选择省份后动态加载城市列表。Vue 提供了多种方式实现联动,包括数据绑定、计算属性、侦听器等。 数据驱动联动 通过 Vue 的…

vue实现卡片

vue实现卡片

Vue 实现卡片组件的方法 使用 Vue 实现卡片组件可以通过多种方式完成,以下是几种常见的实现方法: 使用原生 HTML 和 CSS 在 Vue 单文件组件中,可以通过模板和样式直接实现卡片效果…