在 Vue.js vue-kanban 插件中启用动态输入

Enabling dynamic input in Vue.js vue-kanban plugin

我正在尝试启用 Vue.js vue-kanban 插件 (https://github.com/BrockReece/vue-kanban) 的动态输入。到目前为止,我已经成功创建了一个将用户输入推送到 dynamically-created 块的方法,状态设置为 "on-hold" 以便创建的块在初始 "on-hold" 阶段默认呈现并且然后启用拖放到每个阶段。问题是除了标题之外,我不得不手动输入每个块的 ID。我希望每个块都有一个唯一的 ID,而不必手动输入一个。此外,控制台 returns 错误指示 属性 或 "title" 的方法未在实例上定义,但在渲染期间被引用。解决这两个问题的最佳方法是什么?这是我的代码。谢谢!

//App.vue

<template>
  <div id="app">
    <div class="input-container">
      <input type="number" placeholder="id" v-model="id"/>
      <input type="text" placeholder="title" v-model="title"/>
      <button type="button" v-on:click="addBlock()">Add</button>
    </div>
    <kanban-board :stages="stages" :blocks="blocks">
      <div v-for="stage in stages" :slot="stage" :key="stage">
        <h2>{{ stage }}</h2>
      </div>
      <div v-for="block in blocks" :slot="block.id" :key="block.id">
        <div>
          <strong>id:</strong> {{ block.id }}
        </div>
        <div>
          {{ block.title }}
        </div>
      </div>
    </kanban-board>
  </div>
</template>

<script>
export default {
  name: 'app',
  id: null,
  title: null,
  data () {
    return {
      stages: ['on-hold', 'in-progress', 'needs-review', 'approved'],
      blocks: [],
    }
  },
  methods: {
    addBlock(){
      this.blocks.push({
        id: this.id,
        status: "on-hold",
        title: this.title
      });
      this.status = "";
      this.title = "";
    }
  }
}
</script>

<style lang="scss">
  @import './assets/kanban.scss';

  .input-container {
    width: 50%;
    margin: 0 auto;
  }
</style>

I would like each block to have a unique id without having to manually input one.

也许这会解决问题。

<template>
  <div id="app">
    <div class="input-container">
      <input type="text" placeholder="title" v-model="title"/>
      <button type="button" v-on:click="addBlock()">Add</button>
    </div>
    <kanban-board :stages="stages" :blocks="blocks">
      <div v-for="stage in stages" :slot="stage" :key="stage">
        <h2>{{ stage }}</h2>
      </div>
      <div v-for="block in blocks" :slot="block.id" :key="block.id">
        <div>
          <strong>id:</strong> {{ block.id }}
        </div>
        <div>
          {{ block.title }}
        </div>
      </div>
    </kanban-board>
  </div>
</template>

<script>
export default {
  name: 'app',
  id: 0,
  title: null,
  data () {
    return {
      stages: ['on-hold', 'in-progress', 'needs-review', 'approved'],
      blocks: [],
    }
  },
  methods: {
    addBlock(){
      this.blocks.push({
        id: this.id,
        status: "on-hold",
        title: this.title
      });
      this.id += 1;
      this.status = "";
      this.title = "";
    }
  }
}
</script>