My current singleton pattern is to Vue.extend
the component and call $appendTo(body)
on compile
on the first require
and return the vm
on all others.
When vm.$appendTo
will be removed, I will need another way of creating singleton components..
Maybe something like this:
replace: false
el: => document.body
In vue-comps I have currently 3 singleton components:
waves
instances with the svg animationsI don't quite understand the need for $appendTo()
here - you can just use native DOM methods on this.$el
, what's the difference?
Maybe I'm just confused about
attached deprecated, components no longer have possibility to be off-dom
Will this work?
Comp = Vue.extend(someComp)
vm = new Comp() # vm is off-dom here ?
document.body.appendChild(vm.$el)
if so, this can be closed..
You need to call $mount()
without arguments (which creates vm.$el
) before appending it, but otherwise yes it should work.
Most helpful comment
You need to call
$mount()
without arguments (which createsvm.$el
) before appending it, but otherwise yes it should work.