I am currently working on creating a dynamic component and passing a prop to it. However, I am encountering a warning message that says:
Component is missing template or render function.
Although the component is being rendered, I am still receiving the warning and the prop is not being successfully passed to it.
Parent Section:
<template lang="pug">
q-page
component(:is="detailsComponent" v-bind="selectedRule")
</template>
<script lang="ts">
import { defineComponent, ref, shallowRef, onMounted } from 'vue'
import { useStore } from 'vuex'
import { storeKey } from '../store'
import { useRoute, useRouter } from 'vue-router'
import { RuleList } from '../components/models'
export default defineComponent({
name: 'CodeDetails',
setup() {
const store = useStore(storeKey)
const route = useRoute()
const router = useRouter()
const detailsComponent = shallowRef({})
const selectedRule = ref({} as RuleList)
const selectComponent = async (ruleName: string) => {
let fileName = ''
switch (ruleName) {
case 'retailFoodRules': fileName = 'FoodDetails'
break
case 'generalRules': fileName = 'GeneralDetails'
break
case 'poolRules': fileName = 'PoolDetails'
break
default: fileName = 'OtherDetails'
}
const component = await import(`../components/${fileName}`) as unknown
detailsComponent.value = component.default as RuleList
}
onMounted(() => {
const selected = JSON.parse(route.params.ruleString as string) as RuleList
const ruleName = route.params.rule
if (route.params) {
selectedRule.value = selected as unknown as RuleList
void store.dispatch('searchResults/saveSelectedRule', selected)
// void store.dispatch('searchResults/saveRuleName', ruleName)
void selectComponent(ruleName as string)
} else if (!route.params && store.state.searchResults.selectedRule) {
selectedRule.value = store.state.searchResults.selectedRule
// selectComponent(store.state.searchResults.ruleName)
} else {
router.go(-1)
}
})
return { detailsComponent, selectedRule }
},
})
</script>
Child Component (similar to other dynamic child components):
<template lang="pug">
q-card(flat)
q-card-section
q-item-label.text-caption.text-grey-9 Description
q-item-label.text-subtitle1(v-html="selectedRule.Description")
q-separator
q-card-section
q-item-label.text-caption.text-grey-9 Classification
q-item-label.text-subtitle1(v-html="selectedRule.Classification" :class="{'text-negative': selectedRule.Classification === 'Priority', 'text-orange-9': selectedRule.Classification === 'Priority Foundation'}")
q-separator
q-card-section
q-item-label.text-caption.text-grey-9 Section
q-item-label.text-subtitle1(v-html="selectedRule.Section")
q-separator
q-card-section
q-item-label.text-caption.text-grey-9 Category
q-item-label.text-subtitle1(v-html="selectedRule.Category")
q-separator
q-card-section
q-item-label.text-caption.text-grey-9 Compliance Categories
q-item-label.text-subtitle1(v-html="selectedRule.Compliance")
q-separator
q-card-section
q-item-label.text-caption.text-grey-9 Rule Text
q-item-label.text-subtitle1(v-html="selectedRule.FullText")
</template>
<script lang="ts">
import { defineComponent, toRefs } from 'vue'
import { RuleList } from '../components/models'
export default defineComponent({
name: 'FoodDetails',
setup(props) {
// console.log(Object.assign({}, props))
const selectedRule = toRefs(props.selectedRule as RuleList)
return { selectedRule }
}
})
</script>
Within the child component, I encounter an error that says:
Property 'selectedRule' does not exist on type '{}'.
specifically on the line const selectedRule = toRefs(props.selectedRule as RuleList)
, indicating that the prop passed is not recognized. Strangely enough, when examining the child component using Vue devtools, it shows selectedRule
as an attribute but not as a prop. Is this an oversight on my part or could it be a quirk specific to Quasar?