Batch introduction of vue instructions

like components , create a directives folder in the project directory to store instruction files;
an instruction is a file, and the introduction of main.js files can achieve global introduction;
although many cases are introduced on demand, but want to know how to batch global introduction?

Mar.23,2021

batch global import instructions, which can be registered through forEach traversing Vue.directive

import * as directives from './directives'
// 
Object.keys(directives).forEach(k => Vue.directive(k, directives[k]))

this article can help you understand global instruction wrapper
https://codeshelper.com/a/11.


import Vue from 'vue'

// https://webpack.js.org/guides/dependency-management/-sharprequire-context
const requireDirective = require.context(
  // 
  './directives',
  // 
  false,
  // js
  /.+\.js$/
)

// 
requireDirective.keys().forEach(fileName => {
  // 
  const directiveConfig = requireDirective(fileName)

  const directiveName = fileName
        //  './'
        .replace(/^\.\//, '')
        // 
        .replace(/\.\w+$/, '');
 
  // , 
  Vue.directive(directiveName, directiveConfig.default || directiveConfig)
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3aaff-2ba7e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3aaff-2ba7e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?