[Vuejs]-VueJS how to target the current component and createElement within it?

2👍

Several things.

createElement is a method of document.

This is a very non Vue-like way to go about things. If the component has to update the DOM, whatever you are adding in the mounted method will be removed.

You can get the code to work but I do not recommend it. Not sure what you are trying to accomplish.

console.clear()

Vue.component("test",{
  template: "<div></div>",
  mounted(){
    let test = document.createElement("div")
    test.innerHTML = "this is probably not a good idea"
    this.$el.appendChild(test)
  }
})

new Vue({
  el: "#app",
})
<script src="https://unpkg.com/vue@2.5.2"></script>
<div id="app">
  <test></test>
</div>
👤Bert

Leave a comment