$props


Misol

Qabul qilingan props’ni ko‘rsatish uchun $props obyektidan foydalanish.

<template>
  <div>
    <h3>Received Props</h3>
    <p>This is the $props object:</p>
    <pre>{{ this.$props }}</pre>
  </div>
</template>
Misolni ishga tushirish »

Quyida ko‘proq misollarni ko‘ring.


ULASHISH

Ta’rif va qo‘llanilishi

$props obyekti komponentda e’lon qilingan props’ni ularning joriy qiymatlari bilan birga ifodalaydi.

Vue’dagi props — qiymatlarni bola komponentlarga atributlar sifatida uzatish usuli. Props haqidagi Vue darsligi sahifasiga qarang.

$props obyektidan, masalan, props’ni keyingi bola komponentga uzatish uchun (quyidagi 1-misolga qarang) yoki prop asosida hisoblanadigan (computed) xususiyat yaratish uchun (quyidagi 2-misol) foydalanish mumkin.

$props obyekti faqat o‘qish uchun mo‘ljallangan.


Ko‘proq misollar

1-misol

Props’ni keyingi bola komponentga uzatish uchun $props obyektidan foydalanish.

<template>
  <div>
    <h3>InfoBox.vue</h3>
    <p>This is the $props object that is received from App.vue and passed down to the next child component:</p>
    <pre>{{ this.$props }}</pre>
    <grand-child v-bind="$props" />
  </div>
</template>

<script>
export default {
  props: [
    'bagOwner',
    'bagWeight'
  ]
}
</script>

<style scoped>
div {
  border: solid black 1px;
  padding: 10px;
  margin-top: 20px;
  max-width: 370px;
}
</style>
Misolni ishga tushirish »

2-misol

Sumkaning og‘irligiga qarab izoh xabarini yaratish uchun hisoblanadigan (computed) xususiyatda $props obyektidan foydalanish.

<template>
  <div>
    <h3>InfoBox.vue</h3>
    <p>The $props object is used in a computed value to create a message based on the weight of the bag:</p>
    <span>{{ this.bagWeightStatus }}</span>
  </div>
</template>

<script>
export default {
  props: [
    'bagWeight'
  ],
  computed: {
    bagWeightStatus() {
      if(this.$props.bagWeight>10) {
        return 'Puh, this bag is heavy!'
      }
      else {
        return 'This bag is not so heavy.'
      }
    }
  }
}
</script>

<style scoped>
div {
  border: solid black 1px;
  padding: 10px;
  max-width: 350px;
  margin-top: 20px;
}
span {
  background-color: lightgreen;
  padding: 5px 10px;
  font-weight: bold;
}
</style>
Misolni ishga tushirish »


Tegishli sahifalar

Vue darsligi: Vue komponentlari

Vue darsligi: Vue hisoblangan (computed) xususiyatlar

Vue darsligi: Vue props

Vue darsligi: Vue v-bind direktivasi


W3Schools Pathfinder

Yutuqlaringizni kuzating – bu bepul!