1. Background I was recently interviewing for a job, and the interviewer asked about custom directives. Since I don’t use custom directives very often, I just read the official documentation and roughly knew that I needed to use This is the official documentation module about custom instructions; custom instructions include global custom instructions and local custom instructions 2. Local custom instructions If you want to register local directives, the component also accepts a @Component({ name: "CustomDirectives", components: {}, directives: { // Local custom directive custom1: { inserted(el) { console.log("el", el); el.style.position = "absolute"; el.style.top = "50%"; el.style.left = "50%"; el.style.transform = "translate(-50%,-50%)"; el.innerText = "Loading..."; el.style.padding = "10px"; el.style.color = "#333"; }, }, }, }) 3. Global custom instructionsVue.directive("custom2", { inserted(el, binding) { console.log("binding", binding); if (binding && binding.value) { el.innerText = "Test global custom instructions"; console.log("el", el); el.style.position = "absolute"; el.style.top = "50%"; el.style.left = "50%"; el.style.transform = "translate(-50%,-50%)"; el.style.padding = "10px"; el.style.color = "#333"; } }, }); 4.1 Custom command hook function
4.2 Hook function parameters
Contains the following properties:
4.3 Dynamic instruction parameter transmissionVue.directive("custom2", { inserted(el, binding) { console.log("binding", binding); if (binding && binding.value) { el.innerText = "Test global custom instructions"; console.log("el", el); el.style.position = "absolute"; el.style.top = "50%"; const arg = (binding as any).arg; el.style[arg] = "50%"; el.style.transform = "translate(-50%,-50%)"; el.style.padding = "10px"; el.style.color = "#333"; } }, }); <div v-custom2:[direction]="true"></div> private direction = 'left'; 5. Extension After asking about custom instructions, the interviewer asked you what default instructions you usually use? This is the end of this detailed article about Vue custom instructions. For more relevant Vue custom instructions, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: Solve the problem of blank gap at the bottom of Img picture
1. Use Docker Compose to configure startup If you...
Table partitioning is different from database par...
Why should we read the log? For example, if the c...
It is almost a standard feature for websites nowa...
1. Data desensitization explanation In daily deve...
According to the methods of the masters, the caus...
1. Get the image #Specify the version that includ...
Table of contents 1. Connect to Tencent Cloud Ser...
Sometimes you need to access some static resource...
Table of contents Docker container data volume Us...
Table of contents 1. Enter the network card confi...
Table of contents Standard execution process opti...
Preface All hardware devices in the Linux system ...
Table of contents HTTP hijacking, DNS hijacking a...
This article shares with you the tutorial of inst...