Masalah yang saya hadapi di sini ialah walaupun reporting.type == 'yes'
或 this.$refs.leaders
的值返回为未定义, code>this.$refs.opportunities 即使 reporting.type == 'no'
this.$refs
仅显示 reportingForm
, tiada komponen lain dipaparkan. Tolong bantu saya mengetahui di mana silap saya
<template> <div> <v-card> <v-form :model='reporting' ref='reportingForm'> <v-radio-group v-model="reporting.type" :mandatory="true" class="referral-radios"> <v-radio label="True" :value="'yes'" class="referral-radio"></v-radio> <v-radio label='False' :value="'no'" class="referral-radio"></v-radio> </v-radio-group> </v-form> </v-card> <div> <LeadsResults v-if="reporting.type == 'yes'" :ref="leaders"> </LeadsResults> <OpportunitiesResults v-if="reporting.type == 'no'" :ref="opportunities"> </OpportunitiesResults> </div> </div> </template> <script> import LeadsResults from 'views/leads_results.vue' import OpportunitiesResults from 'views/opportunities_results.vue' export default { components: { LeadsResults, OpportunitiesResults, }, data () { return { reporting: { type: '' } } }, watch: { 'reporting.type': function (value) { if (value == 'yes') { console.log(this.$refs.leaders) //undefined } else if (value == 'no') { console.log(this.$refs.opportunities) //undefined } } } }; </script>
Rujukan templat tidak mengikat
Ubah
kepada