Chapters
48 Chapters
|
5:05:52
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
07.
Creating a Child Component
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This course is also built to work with Vue 3!
What JavaScript libraries does this tutorial use?
// package.json
{
"devDependencies": {
"@symfony/webpack-encore": "^0.30.0", // 0.30.2
"axios": "^0.19.2", // 0.19.2
"bootstrap": "^4.4.1", // 4.5.0
"core-js": "^3.0.0", // 3.6.5
"eslint": "^6.7.2", // 6.8.0
"eslint-config-airbnb-base": "^14.0.0", // 14.1.0
"eslint-plugin-import": "^2.19.1", // 2.20.2
"eslint-plugin-vue": "^6.0.1", // 6.2.2
"regenerator-runtime": "^0.13.2", // 0.13.5
"sass": "^1.29.0", // 1.29.0
"sass-loader": "^8.0.0", // 8.0.2
"vue": "^2.6.11", // 2.6.11
"vue-loader": "^15.9.1", // 15.9.2
"vue-template-compiler": "^2.6.11", // 2.6.11
"webpack-notifier": "^1.6.0" // 1.8.0
}
}
10 Comments
I am using vue 3 and just got the error with the component not being resolved as reported previously by @Trrtr. The solution createApp(App).mount('#app'); should be actually added in the tutorial especially because in one the previous chapters the following is advised for vue 3 which with this chapter will be missing some key probably and that is why it is not complete anymore.
So, for anyone using Vue 3, this won't work anymore here with the component:
const app = createApp({
data: App.data,
render: App.render,
});
Instead use sth similar to:
const app = createApp(App).mount('#app');
The part, setting const app is obviously optional and only if you want to have access to app from e.g. your web tools console.
Hi Armin!
Thanks for the tip! We'll add a comment for it in the right video!
don't work this example
Hey Alexei,
We're sorry to hear you have some troubles with running this example! Do previous examples work for you (examples in previous chapters)? Could you give us a little bit more context? What exactly are you doing? Do you see any errors in Console tab of Google Chrome? We will be happy to assist you if we know a little more about your problem.
Cheers!
Hi, after creating Legend component I'm getting:
<br />[Vue warn]: Failed to resolve component: legend-component at <App><br />Is this issue with vue 3 or am I doing something wrong?
Hey Trrtr,
Hm, my guess is that you need to define your "legend-component" component before you initiate your main instance.
I hope this helps!
Cheers!
What does it mean to define it before main instance? Should I add something to products.js?
Now it looks like this:
`
import { createApp } from 'vue';
import App from './pages/products';
createApp({
}).mount('#app');
`
My products.vue (without template), in which I call <legend-component />:
`
<script>
import LegendComponent from '../components/legend';
export default {
};
</script>
`
And a legend.vue:
`
<template>
</template>
<script>
export default {
};
</script>
`
Everything from products.vue renders correctly except legend-component :(
Hi trrtr!
I'm not sure why would you get such an error in Vue 3. Does it work with Vue 2?
I'd try to instantiate my App as follows:
<blockquote>`
`</blockquote>
And see if that makes it recognize App's child components!
Passing App to createApp worked! Thank you for your help :)
No problem! Looking back at the issue, I know what the problem was: When you do it the first way, you're only passing data and the render function to the Vue engine, not the entire App object. Thus, once you start adding properties to App, those get lost in the way, therefore, you need to change the syntax and just give Vue the entire thing!
"Houston: no signs of life"
Start the conversation!