Answer the question
In order to leave comments, you need to log in
How to pass an instance of a class to components?
Hello.
Structure like this:
Container.js
export default class Container {
constructor(container) {
this.container = container
this.scale = 1
}
setScale(scale) {
this.scale = scale
}
cumulative() {
return Math.PI
}
getCumulativeScale() {
return this.cumulative() * this.scale
}
}
<template>
<div>
Container
</div>
</template>
<script>
import Container from './Container'
export default {
mounted() {
const container = new Container(this.$el)
this.$el.addEventListener('mousedown', (e) => {
let scale = 1//
container.setScale(scale)
})
},
methods: {}
}
</script>
Answer the question
In order to leave comments, you need to log in
Perhaps a plugin will suit you: https://ru.vuejs.org/v2/guide/plugins.html
Or here: https://ru.vuejs.org/v2/api/#provide-inject
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question