jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.78k stars 741 forks source link

How to get data in a component VUE? #236

Closed proyavin closed 3 years ago

proyavin commented 3 years ago
// Main.vue

const ref = this.$refs.drawflow
const newEditor = new Drawflow(ref, Vue, this)

const data = { customField: 'customFieldData' }

this.editor.registerNode('CustomNode', Component, props, options)
this.editor.addNode('nameNewModule', 0, 1, 150, 300, 'github', data, 'CustomNode', 'vue')
// Component.vue

mounted () {
   // How to get `customField` param?
   // console.log(...) -> customFieldData
}
jerosoler commented 3 years ago

Hello @proyavin

Get the id of element with:

  const id = this.$el.parentElement.parentElement.id;

View example: https://github.com/jerosoler/Drawflow/issues/37#issuecomment-717822302

And use function getNodeFromId

proyavin commented 3 years ago

@jerosoler thank you!

hi-reeve commented 3 years ago

is there any way on doing this with the new composition api?

jerosoler commented 3 years ago

Hi @zynth17

It's possible:

<template>
 <div ref="el">Hola</div>
</template>

<script>
import { onMounted, ref } from 'vue'

export default {
  setup() {

   const el = ref(null);

    onMounted(() => {
      console.log(el.value.parentElement.parentElement.id);
    });

    return {
      el
    }
  }
}
</script>

And view:

https://github.com/jerosoler/Drawflow/issues/102#issuecomment-766333278

lemg98 commented 3 years ago

Hello @proyavin

Get the id of element with:

  const id = this.$el.parentElement.parentElement.id;

View example: #37 (comment)

And use function getNodeFromId

I'm getting id on this way but trough me an error when drop a new element. I did this on onMounted hook.

jerosoler commented 3 years ago

View a complete example in https://github.com/jerosoler/Drawflow/issues/263#issuecomment-930449781