ရိုးရိုးလေး ရှင်းပြမယ်
Custom Directives and Plugins ကို ရိုးရိုးလေးနားလည်မယ်
Custom directive ကို low-level DOM behavior ပြန်လည်အသုံးပြုလိုသောအခါသာသုံးပါ။ UI structure ပါလျှင် component သို့မဟုတ် composable ပိုသင့်တော်သည်။ App-wide services နှင့် directives စုစည်းရန် plugin ၏ install(app) ကိုသုံးနိုင်သည်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
ရိုးရိုး template logic ကို directive အဖြစ်ရှုပ်ထွေးစေခြင်း
ဖြစ်လေ့ရှိတဲ့အမှား
Directive event listener ကို unmounted hook တွင်မရှင်းခြင်း
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
DOM behavior အတွက် custom directive နှင့် app-wide capability အတွက် plugin တည်ဆောက်နည်းကို လေ့လာမည်။
- Props / event
- Component + template
- Rendered Vue UI
Custom directive lifecycle ကိုသုံးရန်
အဓိက Syntax / Pattern
<script setup>
const vFocus = {
mounted(element) {
element.focus()
}
}
</script>
<template>
<label>
Search
<input v-focus placeholder="Type to search">
</label>
</template>DOM behavior အတွက် custom directive နှင့် app-wide capability အတွက် plugin တည်ဆောက်နည်းကို လေ့လာမည်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Props / event
<script setup>Custom directive ကို low-level DOM behavior ပြန်လည်အသုံးပြုလိုသောအခါသာသုံးပါ။ UI structure ပါလျှင် component သို့မဟုတ် composable ပိုသင့်တော်သည်။ App-wide services နှင့် directives စုစည်းရန် plugin ၏ install(app) ကိုသုံးနိုင်သည်။
- Component + template
</script>DOM behavior အတွက် custom directive နှင့် app-wide capability အတွက် plugin တည်ဆောက်နည်းကို လေ့လာမည်။
- Rendered Vue UI
</template>Custom Directives and Plugins ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
- Props / event
- Component + template
- Rendered Vue UI
Success
Custom directive lifecycle ကိုသုံးရန်
Failure
ရိုးရိုး template logic ကို directive အဖြစ်ရှုပ်ထွေးစေခြင်း
ရိုးရိုးလေး ရှင်းပြမယ်
Custom directive ကို low-level DOM behavior ပြန်လည်အသုံးပြုလိုသောအခါသာသုံးပါ။ UI structure ပါလျှင် component သို့မဟုတ် composable ပိုသင့်တော်သည်။ App-wide services နှင့် directives စုစည်းရန် plugin ၏ install(app) ကိုသုံးနိုင်သည်။
<script setup>
const vFocus = {
mounted(element) {
element.focus()
}
}
</script>
<template>
<label>
Search
<input v-focus placeholder="Type to search">
</label>
</template>Search input receives focus after mountလက်တွေ့စမ်းကြည့်ရန်
Element အပြင်ဘက် click လျှင် callback ခေါ်သော v-click-outside custom directive တစ်ခုရေးပါ။
Custom Directives — Vue.js
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Custom Directives and Plugins ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Element အပြင်ဘက် click လျှင် callback ခေါ်သော v-click-outside custom directive တစ်ခုရေးပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
<script setup>
const vFocus = {
mounted(element) {
element.focus()
}
}
</script>
<template>
<label>
Search
<input v-focus placeholder="Type to search">
</label>
</template>ရလဒ်: Custom directive lifecycle ကိုသုံးရန်
အရိပ်အမြွက် ကြည့်ရန်
Custom Directives and Plugins ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Props / event → Component + template → Rendered Vue UI
- DOM behavior အတွက် custom directive နှင့် app-wide capability အတွက် plugin တည်ဆောက်နည်းကို လေ့လာမည်။
- ရိုးရိုး template logic ကို directive အဖြစ်ရှုပ်ထွေးစေခြင်း
- Custom Directives and Plugins ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Custom Directives — Vue.js