Your location:Tech News>News>Script>Several VUE global variable implementation

Latest News

Several VUE global variable implementation

Author:fsadmin

Views:

  1, the global variable specific modules

  This means that, this global variable with a management module (js or vue), the module where the variables export (best format for the exported objects, easy call elsewhere) exposed to, when other places need to use, with introduced into the import module

  Global global variable specific modules.vue

  const colorList = [

  ''# F9F900'',

  ''# 6FB7B7'',

  ]

  const colorListLength = 20

  function getRandColor () {

  var tem = Math.round (Math.random () * colorListLength)

  return colorList [tem]

  }

  export default

  {

  colorList,

  colorListLength,

  getRandColor

  }

  Variables in the module with exports exposed to, when other places need to use, can be introduced into the global module.

  Html5 module requires the use of global variables.vue

  

  

  2, mounted to the module global variables Vue.prototype in

  Global.js above, the program''s main entrance.js code below Riga

  import global_ from ''https: // www.jb51.net / article / components / tool / Global ''

  Vue.prototype.GLOBAL = global_

  After loading, the required global amount of the referenced module, do not need to import the global modules, this can be directly referenced as follows:

  

  The difference between 1 and 2 are: 2 not in time to be used in global import demand module file

  3, vuex

  Vuex is designed for a Vue.js application development model of state management.It uses all the components of the centralized storage management application state.Thus kept the overall amount.Because Vuex bit cumbersome, feeling a little overkill.I do not consider it necessary.

  That''s all for this article, I want to be helpful to learn, I hope you will support script Home.

  How to set up methods vue define global variables and methods of introducing methods example vue Vue introduced sass sass global variables and configure global variables global variables or data vue global variables inside method vue2 Discussion: You may be interested in articles how to define global variables and functions defined in various ways Vue global variables and constants vue explain how to add a title to set global functions or global variables as well as single-page summary Detailed VUE define global variables in the implementation of several projects vue

Recommend article

Relate article