doujiazong0322 2019-04-23 17:21
浏览 50

如何将mysql查询数据插入到任务卡列表的vue.component中

I'm building task/cards each with lists and need to add list items to the cards via mysql query. I need help to replace the static list entries with information from a mysql query to the vue data in java script?

I have all of the front end code working properly but only with the static list. Once I figure out how to auto fill the card with the mysql query data I should be able to figure out the inserts and edits on my own.

#HTML Snippet
<div id="vue-example">
  <div id="drag-scope">
    <div class="column">
      <div class="title">Monday</div>
      <todo-container class="regular green lighten-6" :data="todos.monday">
        <todo-item v-for="(todo, index) in todos.monday" :data="todo" @remove="todos.monday.splice(index, 1)"></todo-item>
      </todo-container>
    </div>
  </div>
</div>


#Java Script
<script> 
Vue.component('todo-container', {
  template: '<div class="todo-container"><slot></slot></div>',
  props: ['data']
});
Vue.component('todo-item', {
  template: `
<div class="z-depth-3 todo-item">
<div class="content lmdd-block">
<i class="material-icons handle">reorder</i>
<a class="remove" @click="$emit('remove')"><i class="material-icons">clear</i></a>
<div class="task">{{data}}</div>
</div>
</div>
`,
  props: ['data']
})
var vueExample = new Vue({
  el: '#vue-example',
  data: {
    newTodoText: '',
    todos: {
      sunday: [],
      monday: [],
      tuesday: [],
      wednesday: [],
      thursday: [],
      friday: [],
      saturday: [],
      regular: [
        'list item1',
        'list item2',
        'list item3'
      ],
      priority: [],
      done: []
    }
  },
  mounted: function() {
    lmdd.set(document.getElementById('drag-scope'), {
      containerClass: 'todo-container',
      draggableItemClass: 'todo-item',
      handleClass: 'handle',
      dataMode: true
    });
    this.$el.addEventListener('lmddend', this.handleDragEvent);
    this.$el.addEventListener('lmddstart', this.handleDragStart);
  },
  methods: {
    handleDragStart: function() {
       this.dragEvent = true;
     },
    handleDragEvent: function(event) {
      var newIndex = event.detail.to.index;
      var oldIndex = event.detail.from.index;
      var newContainer = event.detail.to.container.__vue__.data;
      var oldContainer = event.detail.from.container.__vue__.data;
      if (event.detail.dragType === 'move') {
        newContainer.splice(newIndex, 0, oldContainer.splice(oldIndex, 1)[0]);
      }
    },
    addNewTodo: function() {
      this.todos.regular.push(this.newTodoText)
      this.newTodoText = ''
    }
  }
})
</script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源