2

I would like to create Side Panel as a reusable component in Framework7 with VueJS. Here is my code..

project structure

Card.vue

<f7-card>
  <f7-card-header>Card header content</f7-card-header>
  <f7-card-content><img src="https://wiki.videolan.org/images/Ubuntu-logo.png"></img></f7-card-content>
  <f7-card-footer>Card footer content</f7-card-footer>
</f7-card>

Now i registered as a component like below,

import Vue from 'vue'
export default [
    {
        path: '/card/',
        component: require('./Card')
    },
]

In later vues i imported as,

import Card from './Card.vue'

and i try to access in another vues like,

Now i'm getting an error like

[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

Can anyone help me where have i mistaken?

Thanks,

0

3 Answers 3

3

It's not really clear from your code exactly what you are doing, but the error you are getting happens when you try to use a component as a child of another component without registering it in the parent's components setting like this:

<script>
import Card from './Card.vue'

export default {
  data () {
    return {
       somedata: 'some value'
    }
  },
  components: {Card: Card}, // <- you're missing this
  // etc...

}
</script>

You can also register components globally. More here: https://v2.vuejs.org/v2/guide/components.html#Local-Registration

Sign up to request clarification or add additional context in comments.

1 Comment

Again it is saying that... Failed to mount component: template or render function not defined. (found in <Card>... I even added components: {Card, Card};
1

Are you showing us all of Card.vue? For a valid single-file vue component, I would expect to see <template>, <script> and <style> elements. The render function will be generated from whatever you put in the <template> element.

2 Comments

Adding <template>, <script> and <style> solved my problem... Now it is working with only one component.. when i try to add one more component by giving comma it is not accepting "You may need an appropriate loader to handle this file type. | } | }, | components: {FSidebar,FSidebar},{CSidebar,CSidebar}"
components is one object, inside which you have 'name':object, 'name':object. try components = {'FSidebar':FSidebar,'CSidebar':CSidebar}
0

Make sure that the component that you want to reuse is wrapped inside a template tag As follows

<template>
    <div>
        <component data/>
    <div/>
<template/>

Then register it inside the parent Like so

export default {
  name: "Card",
  components: {
    Card
  },
};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.