1

I want to create a Javascript class that I can instantiate from a Vue component and call functions on it like in C#.

public class MyClass()
{
        public MyClass(string someParameter){
        ....initialization code using "someParameter"
       }

        public String SomeProperty {get; set;}

        public void MyClassMethod(){
        ....my code goes here
        }    
}

In Vue, I'd import JavaScript "functions" using the "Import" keyword but here I'd like to import the entire object and call the functions on it. I'm thinking that an IFFE might be the way but not sure. My question is 1) is it possible and 2) if so, how should I structure it AND how would I call/or instantiate the object from Vue code?

GrassFed
  • 35
  • 1
  • 8

1 Answers1

0

If you are using Vue.js, I think the better way will be to stick with vue component based structure and use mixins.

(https://v2.vuejs.org/v2/guide/mixins.html)

tony19
  • 125,647
  • 18
  • 229
  • 307
Sarmad
  • 315
  • 1
  • 4
  • 15
  • That's a good option but not sure it's the best one for my scenario. It appears too tightly coupled with the Vue component. Basically I'd just like to import and instantiate a js object w parameters and call function methods on it at various intervals. I'd like to keep the design as loose and as possible as the component may need to be used in other applications. – GrassFed Jul 31 '20 at 00:47