VUE uses the unique global variable, function, and the instance code of the filter

do not speak a human hair, using mixins mixed to achieve global variables and functions. mixins inside methods, variables, and filters will be inside the assembly method, variable filter combined. This approach will have the advantage of ide methods, variables, filter tips.

a, main.js document

  import Vue from 'vue' import App from './App' import router from './router' import store from './store'import mixin from' ./utils/mixin 'Vue.prototype. $ bus = new Vue () // globally mixed Vue.mixin (mixin) new Vue ({store , router, render:. h => h (App),}) $ mount ( '# app')  

a, mixin.js file, the method I , variables, filters the three were written three js file inside, post-maintenance convenience. May be written directly to the file which mixins

  import filters from './filters'import globalMethods from' ./global-methods'import Config from '../config' import CONSTANT from './const_var'// mixed global export default {data () {return {CONFIG: Config, CONSTANT,}}, methods:{// // Mount the method in the GlobalMethods file to Vue to make it easy to call, directly this. $ Xxx method name can be // Object.keys (GlobalMethods) .foreach (key => {// Vue. Prototype [Key] = Tools [key] //}) // The method in GlobalMethod is mixed into the Mixin with object universal, which is easy to call, directly this. $ xxx method name ... globalmethods,}, Filters: {// // adds the method of the Filter Adds the Vue filter // Object.keys (filters) .fore can (key => {// vue.filter (key, filters [key]) //} ... filters,},}  
Filters.js file

Export default {// Time conversion Date (v) {…}, // handled ID card information, hidden processidNumber (v) {…},}
 Global-Methods .js file   
Import {Message, MessageBox} from ‘Element-ui’Export default {$ success (msg) {…}, $ warning (msg) { …}, $ error (msg) {…}, $ checkplatform () {…}, // Countdown time format $ countdownformattime (timestamp) {…},}

constant_var.js file
   export default {redirect: 'redirect', // request method Post: 'post', get: 'get', PATCH: 'PATCH', DELETE: 'DELETE', PUT: 'PUT', // Static Constant PickerOptions: {...}, Pagenumber: 1, PageSize: 10, DelayTime: 250, Success: '000000',}
Summary

The above is the example of the VUE introduced by Xiaobian to define a global variable, function, and filter instance. Code, I hope to help everyone, if you have any questions, please leave a message, Xiaobian will reply to everyone in time. Thank you very much for your support of Tumi Cloud Website! If you think this article helps you, welcome to reprint, please indicate the source, thank you!
                     
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment