# 1. 父子组件生命周期执行顺序

  • 加载渲染过程
    父: beforeCreate -> created -> beforeMount
    子: beforeCreate -> created -> beforeMount -> mounted
    父: mounted
  • 更新过程
    父: beforeUpdate
    子: beforeUpdate -> updated
    父: updated
  • 销毁过程
    父: beforeDestroy
    子: beforeDestroy -> destroyed
    父: destoryed
<template>
	<HotCurve :areaId="startCode" :curTemp="temperatureNum" ref="hotCurve"/>
	<TempBar :areaId="startCode" ref="tempBar"/>
</template>

加载渲染过程
父  beforeCreate、created、beforeMount
子(HotCurve) beforeCreate、created、beforeMount
子(TempBar) beforeCreate、created、beforeMount
子(HotCurve) mounted
子(TempBar) mounted
父  mounted

# 2. prop的validator方法

使用 prop 定义中的 validator 选项,可以将一个 prop 类型限制在一组特定的值中。

<script>
export default {
	name: 'Image',
	props: {
	    src: {
			type: String,
	    },
	    style: {
			type: String,
			// 这个验证函数接受一个prop,如果prop有效或无效,则返回true或false。
	      	validator: s => ['square', 'rounded'].includes(s)
	    }
  	}
}
</script>