Apply global variable to Vuejs

前端 未结 8 1409
谎友^
谎友^ 2020-12-02 15:02

I have a javascript variable which I want to pass globally to Vue components upon instantiation thus either each registered component has it as a property or it can be acces

8条回答
  •  离开以前
    2020-12-02 15:53

    A possibility is to declare the variable at the index.html because it is really global. It can be done adding a javascript method to return the value of the variable, and it will be READ ONLY. I did like that:

    Supposing that I have 2 global variables (var1 and var2). Just add to the index.html header this code:

      
    

    It's possible to do a method for each variable or use one single method with a parameter.

    This solution works between different vuejs mixins, it a really global value.

提交回复
热议问题