[Vuejs]-Get computed property and pass its value while editing another text field vue.js

0πŸ‘

βœ…

It was simple in the end so fyi the changed code that worked, adding this.

<template>
  <div class="editor">
    <form id="editForm">
      <h2>Edit</h2>
      <button @click="closeEdit()">Close</button>
      <textarea
        v-model="activeNote.text"
        @input="editNote"
        class="form-control"
      ></textarea>
      <input v-bind:value="activeNote.id" name="id" readonly />
    </form>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  methods: {
    editNote(e) {
      this.$store.dispatch('editNote', e)
      this.$store.dispatch('noteId', this.activeNote.id)
    },
    closeEdit() {
      this.$emit('closeEdit')
    }
  },
  computed: mapState({
    activeNote: state => state.activeNote
  })
}
</script>

Leave a comment