0
I’m using the single file components
, but I can’t access a component via another component, follow what I tried...
<template>
<div id="containerPrincipal" @click.stop="teste">
...
<template>
<script>
/*Outro componente*/
import flex_div from './elementos/Div.vue'
export default {
name: 'containerPrincipal',
methods : {
teste () {
componente = new flex_div().$mount();
console.log(componente);
}
},
components: {
flex_div
}
}
</script>
Error
_Div2.default is not a constructor
How can I fix this?
Edit
Div.Ve.
<template>
<div id="flexdiv" @click.stop="opcoes">
...
</template>
<script>
export default {
name: 'flexdiv',
data () {
return {
modal : false,
eventMod : false,
elMod : false,
}
},
methods : {
opcoes (event) {
if(this.modal === true) {this.modal = false;}
else {this.elMod = event.target; this.eventMod = event; this.modal = true;}
}
<style scoped>
#flexdiv {
background: #424242;
height: 200px;
width: 400px;
}
</style>
Want to add that component multiple times or just once? Can you explain what you’re doing in the application that needs that component?
– Sergio
@Sergio, everything in my application is generated dynamically, this component, will be added several times and each time it is added will have to be treated individually, so I did it this way. there will be nothing predefined.
– Felipe Duarte
And it should be added to the right DOM? You want to insert several in the same place (together with others) or in different places in the DOM?
– Sergio
@Sergio I’ll try to explain, I have an initial component, when I click on this component, will open a menu with several options among them stylize the component, add elements etc... if I add an element in the component, example a div, this div will have the same options as the initial component or when I click this div, it can be stylized and can receive other elements and so on, follow an example of this I said https://jsfiddle.net/044euft5/2/
– Felipe Duarte