question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The Vue3 unMounted event will not be triggered when using removeNodeId and clear

See original GitHub issue

Hi, I found a problem. The Vue3 unMounted event will not be triggered when using removeNodeId and clear.

test demo

App.vue:

<template>
  <div>
    <button @click="remove">remove</button>
    <div class="box"></div>
  </div>
</template>

<script>
import HelloWorldVue from "./components/HelloWorld.vue";
import { h, ref, render, defineComponent, onMounted } from "vue";
import Drawflow from "drawflow";
import "drawflow/dist/drawflow.min.css";

const Vue = { version: 3, h, render };
export default defineComponent({
  name: "App",
  components: {},
  setup() {
    const editor = ref();

    onMounted(() => {
      editor.value = new Drawflow(document.querySelector(".box"), Vue);
      editor.value.registerNode("hello", HelloWorldVue, {}, {});
      editor.value.start();
      editor.value.addNode("ddd", 1, 1, 200, 200, "ddd", {}, "hello", "vue");
    });

    const remove = () => {
      editor.value.removeNodeId("node-1");
    };

    return {
      remove,
    };
  },
});
</script>

HelloWorld.vue

<script>
export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },

  mounted() {
    console.log("component mount");
  },

  unmounted() {
    console.log("component unmount");
  },
};
</script>

Look console, not show “component unmount” when clicking the remove button.

How to solve it?

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rni-lcommented, Mar 29, 2022

@rni-l Thanks! Yeah, I have something similar. My issue is when I clear it programmatically or when navigating away. I can’t get the unmount then.

@tomasp1189

Sorry, I don’t understand what you mean. Can’t trigger unmount event in inserted component via Drawflow when you are using navigation?

Like this? It will trigger a remove event when the page changes navigation.

// main page
export default {
  unmounted() {
    eventBs.emit("remove");
  }
}

// child component
export default {
  mounted() {
    // listen
    eventBus.on("remove", () => {
      // ...
    });
  }
}
0reactions
tomasp1189commented, Mar 29, 2022

@rni-l Thanks! Yeah, I have something similar. My issue is when I clear it programmatically or when navigating away. I can’t get the unmount then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VUE 3 Force unmount when deactivated - Stack Overflow
What I want to do is to unmount a page-component from keep-alive cache when it is deactivated . /* this is the loaded...
Read more >
Event handlers fire after `umounted`. Unlike Vue 2 ... - GitHub
Event handlers should not run after a component is unmounted. As it stands, this is an undocumented breaking change between Vue 2 and...
Read more >
Options: Lifecycle | Vue.js
However, the mounting phase has not been started, and the $el property will not be ... Called right before a component instance is...
Read more >
A Complete Guide to Vue Lifecycle Hooks - with Vue 3 Updates
beforeCreate() – Options API. Since the created hook is the thing that initializes all of the reactive data and events, beforeCreate does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found