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
So after registering a domain name and purchasing...
Pull the image root@EricZhou-MateBookProX: docker...
Before starting the main text of this article, yo...
The following code introduces MySQL to update som...
If you often use FTP server in your study or work...
Transaction isolation level settings set global t...
Table of contents Preface Basic Usage grammar Err...
This article example shares the specific code of ...
1. Usage of instanceof instanceof operator is use...
This article shares two methods of implementing t...
This is the installation tutorial of mysql5.7.18....
introduction I discovered a problem before: somet...
<br />Maybe you've just come into a comp...
This article shares the specific code of JavaScri...
1. Download the MySQL jdbc driver (mysql-connecto...