Vue 3 - "Unable to resolve component" warning
P粉451614834
P粉451614834 2023-08-26 13:03:49
0
1
414
<p>I encountered this warning when trying to import a component from my index.js file. </p> <p>This is my components folder: </p> <pre class="brush:php;toolbar:false;">components/ |-- index.js |-- ComponentA.vue |-- ComponentB.vue |-- ComponentC.vue</pre> <p> and index.js: </p> <pre class="brush:php;toolbar:false;">import ComponentA from './ComponentA'; import ComponentB from './ComponentB'; import ComponentC from './ComponentC'; export { ComponentA, ComponentB, ComponentC };</pre> <p>When I try this in any component (B or C)</p> <pre class="brush:php;toolbar:false;"><script> import { ComponentA } from './'; console.log(ComponentA); // undefined export default { components: {ComponentA} } </script></pre> <p>I get a warning in the console, how do I fix it? What am I doing wrong here? </p> <p>By the way, this method works:</p> <pre class="brush:php;toolbar:false;">import ComponentA from './ComponentA';</pre> <p>But I don't want to use this method because I have many components in <code>components</code> folder</p>
P粉451614834
P粉451614834

reply all(1)
P粉600845163

You should write the import statement in the following form:

<script>
import { ComponentA } from './components';

export default {
    components: { ComponentA }
}
</script>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!