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了

如图:

原文地址:https://www.cnblogs.com/eyed/p/10677879.html