props 父組件給子組件傳遞參數


話不多說,直接上代碼

父組件:

<span><humidity-component ref="soilHumidityBot" :title='title2'></humidity-component></span>
data () {
      return {
        title2: '土壤濕度'
       
      }
    }

在子組件HumidityComponent.vue中:

data () {
      return {
        myChart: ''
      }
    },
    props: {
      title: {
        type: String,
        default: ''
      }
    }

然后調用的時候直接this.title就可以了,

在頁面上就會顯示“土壤濕度”這個title了

如圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM