如何在vue中注册全局指令 #7298
Unanswered
WhisperCode
asked this question in
Help/Questions
如何在vue中注册全局指令
#7298
Replies: 2 comments 9 replies
-
custom-directives Write directly in 'main. ts' const app = createApp(App);
app.directive('color', (el: HTMLElement, binding: DirectiveBinding) => {
el.style.color = binding.value;
}); Import to 'main. ts' for registration import Bold from './directive/bold';
const app = createApp(App);
app.directive('bold', Bold); If there are many instructions, you can write a batch registration function. |
Beta Was this translation helpful? Give feedback.
8 replies
-
正如 @chenxch 的回答 #7298 (comment) ,文档 https://cn.vuejs.org/api/application.html#app-directive 中也有提到。 As mentioned in @chenxch's answer #7298 (comment) and in the documentation https://cn.vuejs.org/api/application.html#app-directive |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
当我们需要用到很多的自定义指令的时候,而且还用到了ts,如何在main.ts中注册全局指令?
Beta Was this translation helpful? Give feedback.
All reactions