新建文件夹directive,创建index.ts
import { App } from 'vue'
export default (app: App<Element>) => {
//自定义组件
app.directive('focus', (el: HTMLElement, binding) => {
el.addEventListener('click', () => {
console.log(66);
})
});
}
main.ts
import { createApp } from "vue";
import App from "./App.vue";
import { router } from "./router/index";
import { store, key } from "./store/index";
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
import "@/assets/styles/common.css";
import directives from '@/directive/index' //自定义指令导入
createApp(App)
.use(directives) //这里引入
.use(Antd)
.use(router)
.use(store, key)
.mount("#app");