vuejs2 - For recursive components, make sure to provide the "name" option -
i have created component this
<template> <span class="my-icon"> <img :src="isrc" :alt="iname" /> </span> </template> <script> export default { props: ['iname'], computed: { isrc() { return require('../../../assets/images/' + this.iname + '.png') } } } </script>
using inside page like
<template> <div> <h3>share it:</h3> <social-sharing inline-template network-tag="a"> <div class="my-icons"> <network network="facebook" class="fb-icon"> <icon name="fb" /> </network> </div> </social-sharing> </div> </template> <script> import icon '~/comps/icon.vue' export default { components: { icon } } </script>
which throwing error
[vue warn]: unknown custom element: <icon> - did register component correctly? recursive components, make sure provide "name" option.
social-sharing vuejs plugin, if use icon component outside social-sharing works fine, inside throws error.
this because using inline-template
special attribute on <social-sharing>
component.
from documentation:
when inline-template special attribute present on child component, component use inner content template, rather treating distributed content.
everything inside <social-sharing>
tag being treated if template definition component. and, since <icon>
component being registered outside <social-sharing>
component's scope, doesn't know <icon>
tag.
since looks <social-sharing>
component dependant on inline-template
definition, thing can think register <icon>
component globally:
// in main.js file import icon '~/comps/icon.vue' vue.component('icon', icon);
then, since <icon>
component in global scope, <social-sharing>
component have reference it.
Comments
Post a Comment