$parent
Misol
Ota komponentdagi "text" data xususiyatini o‘zgartirish uchun bola komponentda $parent obyektidan foydalanish.
<template>
<div>
<h3>Change Text</h3>
<p>Click the button to toggle the text in the PRE tag of the parent component.</p>
<button v-on:click="this.$parent.text='Hello!'">Change text in parent</button>
</div>
</template>
Misolni ishga tushirish »
Quyida ko‘proq misollarni ko‘ring.
Ta’rif va qo‘llanilishi
$parent obyekti ota komponentning Vue nusxasini ifodalaydi.
Agar root komponentida $parent obyekti ishlatilsa, $parent obyektining qiymati null bo‘ladi.
$parent obyektidan bola komponent ichidan ota nusxaga to‘g‘ridan-to‘g‘ri murojaat qilish, metodlarni chaqirish, data xususiyatlarini o‘qish yoki o‘zgartirish va hokazolar uchun foydalanishimiz mumkin.
Eslatma: Vue komponentlari o‘rtasidagi aloqa uchun buning o‘rniga props/emit yoki provide/inject’dan foydalanishni o‘ylab ko‘ring, chunki aloqa usullari aniq belgilangan kodni qo‘llab-quvvatlash osonroq.
Ko‘proq misollar
Misol
Ota komponentdagi metodga murojaat qilish uchun bola komponentda $parent obyektidan foydalanish.
<template>
<div>
<h3>Toggle Color</h3>
<p>Click the button to toggle the color in the P tag of the parent component.</p>
<button v-on:click="this.$parent.toggleColor">Toggle</button>
<p>The 'toggleColor' method is also in the parent component.</p>
</div>
</template>
Misolni ishga tushirish »
Tegishli sahifalar
Vue darsligi: Vue props
Vue darsligi: Vue $emit() metodi
Vue darsligi: Vue Provide/Inject
Vue ma’lumotnomasi: Vue $emit() metodi
Vue ma’lumotnomasi: Vue $root obyekti
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
