$attrs
Misol
id fallthrough atributini <p> tegiga yo‘naltirish uchun $attrs obyektidan foydalanish.
<template>
<h3>Tigers</h3>
<img src="/img_tiger_small.jpg" alt="tiger">
<p v-bind="$attrs">Tigers eat meat and not plants, so they are called carnivores.</p>
</template>
Misolni ishga tushirish »
Quyida ko‘proq misollarni ko‘ring.
Ta’rif va qo‘llanilishi
$attrs obyekti komponent tegida berilgan fallthrough atributlar va hodisa tinglovchilarini ifodalaydi.
Agar root element komponent tegida berilgan fallthrough atributlar va hodisa tinglovchilarini meros qilib olishini istasak, o‘sha elementda v-bind="$attrs" ifodasidan foydalanamiz.
$attrs obyekti faqat o‘qish uchun mo‘ljallangan.
Fallthrough atributlar — komponent tegida berilgan atributlar (props emas) bo‘lib, ular komponentning root elementiga o‘tadi. Agar komponentda bir nechta root element bo‘lsa, fallthrough atributlarni qaysi element meros qilib olishi kerakligini belgilash uchun $attrs obyektidan foydalanamiz. Fallthrough atributlar haqida darslikda batafsil bilib oling.
Ko‘proq misollar
1-misol
id va title fallthrough atributlarini hamda ularning qiymatlarini ko‘rsatish uchun $attrs obyektidan foydalanish.
<template>
<h3>Tigers</h3>
<img src="/img_tiger_small.jpg" alt="tiger">
<p v-bind="$attrs">Tigers eat meat and not plants, so they are called carnivores.</p>
<hr>
<p><strong>Below is the content of the $attrs object:</strong></p>
<pre>{{ attrsObject }}</pre>
</template>
<script>
export default {
data() {
return {
attrsObject: null
}
},
mounted() {
console.log(this.$attrs);
this.attrsObject = this.$attrs;
}
}
</script>
<style>
#pink {
background-color: pink;
border-radius: 15px;
padding: 10px;
}
img {
width: 100%;
border-radius: 15px;
}
</style>
Misolni ishga tushirish »
2-misol
Ota komponentdan hodisa tinglovchisini qabul qilish uchun <img> tegida $attrs obyektidan foydalanish.
<template>
<h3>Toggle Image Size</h3>
<p>Click the image to toggle the image size.</p>
<img v-bind="$attrs" src="/img_tiger_small.jpg" class="imgSmall">
</template>
<style>
.imgSmall {
width: 60%;
}
.imgLarge {
width: 100%;
}
img {
border-radius: 15px;
cursor: pointer;
}
</style>
Misolni ishga tushirish »
Tegishli sahifalar
Vue darsligi: Vue fallthrough atributlari
Vue darsligi: Vue metodlari
Vue darsligi: Vue v-bind direktivasi
Vue darsligi: Vue v-on direktivasi
Vue ma’lumotnomasi: Vue v-bind direktivasi
Vue ma’lumotnomasi: Vue v-on direktivasi
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
