Vue3注册全局指令

在src目录下新建directives

permission.js文件

export default {
  name: 'action',
  mounted(el, binding, vnode) {
    console.log(vnode.ctx, 'vonde')
    // debugger
    const rolesList = ['add', 'edit', 'list']
  }
}

index.js文件

import permission from "./permission";
// 注册全局自定义指令
const directive = [permission]

export default (app) => {
  directive.forEach((directive) => {
    app.directive(directive.name, directive)
  })
}

main.js文件

import directives from './directives/index';
directives(app)

你可能感兴趣的:(javascript,前端,vue.js)