1. 程式人生 > >vue props 拿不到值的解決方案

vue props 拿不到值的解決方案

方案一:
在子元件中設定v-if=’flag’,初始值false,在成功獲取資料後設置為true

// 子元件
 <echarts :datas="conditionStatisticsData" v-if="flag"></echarts>
// 成功獲取資料後 flag設定成true
 homeResource.getConditionData().then((res) => {
  this.flag = true
   if (res.data.status === 0) {
     console.log('條件', res.data.data)
     this
.conditionStatisticsData = res.data.data } })

方案二:
watch監聽props傳遞過來的值,在裡邊執行方法

 watch: {
  datas: function (val) {
     this.chartsInit(val)
   }
 },