The problem I'm facing here is that even if reporting.type == 'yes'
or the value of this.$refs.leaders
is returned as undefined, code>this. $refs.opportunities returns undefined even if reporting.type == 'no'
this.$refs
Only reportingForm
is displayed and no other components are displayed. Please help me figure out where I'm going wrong
<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>
Template reference is not binding
Change
to