欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解vue父子組件間傳值(props)

 更新時(shí)間:2017年06月29日 10:03:32   作者:ygtq  
本篇文章主要介紹了詳解vue父子組件間傳值(props),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

先定義一個(gè)子組件,在組件中注冊(cè)props

<template>

  <div>

    <div>{{message}}(子組件)</div>

  </div>

</template>

<script>

export default {

  props: {

    message: String //定義傳值的類型<br>  }

}

</script>

<style>

</style> 

在父組件中,引入子組件,并傳入子組件內(nèi)需要的值

<template>

  <div>

    <div>父組件</div>

    <child :message="parentMsg"></child>  

  </div>

</template>

 

<script>

 

import child from './child' //引入child組件

export default {

  data() {

      return {

        parentMsg: 'a message from parent' //在data中定義需要傳入的值

      }

    },

    components: {

      child

    }

}

</script>

<style>

</style> 

這種方式只能由父向子傳遞,子組件不能更新父組件內(nèi)的data

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論