title: Remove ANY Grid-Item on the click of an 'x' button that is within each item, my method only deletes the last one
body: <p>I am re-vamping a program for my Engineering departments research team, my app has been built using Electron, Vuex, HTML/Sass/Javascript. The program's purpose is to allow the user to create "steps" which are items/tiles that you can go into &amp; set system parameters &amp; processes to run X amount of times. Setting up the values and settings within each step can take a while, so if the user creates 5 steps, and realizes they want to delete step number 2 entirely, there needs to be a 'remove' or a small 'x' within each step/item. Currently, I can only remove the last populated step/item using the 'pop' function to remove the last item in the array 'stepsGrid'.</p>
  
  <p>Using vue-grid-layout to populate grid-items/tiles which will each be a 'step' that our system will run. I am able to dynamically add new 'steps', however I have only been able to successfully remove steps by using pop() to remove the last item from the array in which grid-items are. I want to place a</p>
  
  <pre><code>&lt;button id="remove" @click="removeStep()"&gt;Remove&lt;/button&gt;
  </code></pre>
  
  <p>within each step, so that I can delete any item on the grid instead of just the last item.</p>
  
  <p>I have seen a few examples, but not being the best at javascript- I haven't had any luck. I tried referencing the functions used here: <a href="https://chrishamm.io/grid-demo/" rel="nofollow noreferrer">https://chrishamm.io/grid-demo/</a>
  and  <a href="https://github.com/chrishamm/vue-dynamic-grid" rel="nofollow noreferrer">https://github.com/chrishamm/vue-dynamic-grid</a>
  for removing grid items, however this library is a little more complicated than the regular Vue-Grid-Layout.</p>
  
  <p>Here is my code, the key is the step.i component which is the ID of each item populated, each tile will have an 'x' in the corner and the function needs to be able to recognize the ID of that tile, and delete the corresponding item from the stepsGrid array:</p>
  
  <pre><code>&lt;h2 style="color: #f6a821;"&gt;Steps&lt;/h2&gt;
  &lt;hr class="hr" /&gt;
  &lt;grid-layout
    :layout.sync="stepsGrid"
    :col-num="8"
    :row-height="75"
    :is-draggable="true"
    :is-resizable="false"
    :is-mirrored="false"
    :vertical-compact="true"
    :margin="[50, 50]"
    :use-css-transforms="true"&gt;
  
  &lt;grid-item
    v-for="step in stepsGrid" :key= "step.i"
    :x="step.x"
    :y="step.y"
    :w="step.w"
    :h="step.h"
    :i="step.i"
    :isDraggable="step.isDraggable"&gt;
  
  &lt;div class="Panel__name"&gt;Step: {{step.i}} //displays item # on each tile
  &lt;div class="Panel__stepcount"&gt; Loop Count: &lt;input type="number" value="1"&gt;
   &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="editButton"&gt;
  &lt;div class="Panel__status"&gt;Status:&lt;/div&gt;
  &lt;button @click="removeStep()"&gt;Remove&lt;/button&gt;
  
  
  &lt;/grid-item&gt;
  &lt;/grid-layout&gt;
  </code></pre>
  
  <p>//Grid arrays are in store.js, as shown below(this is for an electron app):</p>
  
  <pre><code>import Vue from 'vue';
  import Vuex from 'vuex';
  import createPersistedState from 'vuex-persistedstate'
  
  Vue.use(Vuex);
  
  export const store = new Vuex.Store({
  state: {
   stepsGrid : [
  {"x":0,"y":0,"w":2,"h":1,"i":"0"}
  ],
  
  mutations: {
  addStep (state, step){
  state.stepsGrid.push(step);
  }
  },
  
  actions: {
    addStep ({state, commit}){
      const step = 
      {"x":0, "y": 1, "w": 2,"h":1,"i":String(state.stepsGrid.length) };
      commit('addStep', step);
   },
  </code></pre>
  
  <p>I know I need to incorporate the use of a key here, but I am unsure how to do it. I found this, but he goes about it an unusual way:</p>
  
  <p>"I deleted the element in array by the button and could not understand the problem, as the last element was always deleted, although the key was unique. I added an extra unique uuid and it all worked."</p>
  
  <pre><code>&lt;dish-item v-else class="dishItem" 
  v-for="(item, key) in dishes" :key="key + $uuid.v1()" :value="item"
  @removeDish="$delete(dishes, key)" 
  @editDish="$refs.modal.showEdit({item, key})"
  /&gt;
  </code></pre>
  
  <p>Lastly, I went digging through the files for Vue-Dynamic-Grid and found that they are removing items with the following method:</p>
  
  <pre><code>methods: {
      removeElement(item) {
      if (item == this.selectedItem) {
      this.selectElement(null);
  }
  
  this.gridItems.splice(item.i, 1);
  this.items.splice(item.i, 1);
  breakpoints.forEach(function(size) {
      this.layouts[size].splice(item.i, 1);
      this.layouts[size].forEach(function(layout, i) {
         if (layout.i &gt; item.i) {
           layout.i--;
          }
      });
  }, this);
  this.$emit("itemRemoved", item);
      }
  </code></pre>
  
  <p>If anyone could be of help, I would appreciate it! I have been learning JS on the go with this project, so if anyone has some tips please let me know! Thanks</p>
  
  <p>I have tried attempting to write a function based on the way Vue-Dynamic-Layout's method for removing items, but I was not successful. As of right now, I don't have a small 'x' in each tile, I have a button for adding/removing a step in the bottom left of my app, to remove items I am simply popping the last item out of the stepsGrid array, so I can only remove the last populated item.</p>