vue: Mount a Vue Application to the DOM and Render Reactive Knowledge


Trainer: [0:00] We have now the information set as much as lend a hand us be informed Vue, so let’s get caught in. In our major.js document, we’re going to delete this check variable, and we can instantiate a Vue application, const app will equivalent Vue.createApp. This serve as is located at the Vue object, and it takes a configuration object.

[0:23] Right through this path, we’re going to upload various things to our configuration object, however the very first thing we’re going to upload is a knowledge serve as. This information serve as returns an object, that are the homes that we wish to be reactively to be had inside of our Vue application. On this case, let’s make identify to be had, and let’s name it, comedy occasions.

[0:47] If I am going to my console, I will be able to see that that application has been outlined. What we wish to do is mount this Vue application onto a component in our HTML. Let’s go back to our index.HTML. Let’s eliminate this Hello. Let’s give this div an ID. Now, this ID will also be no matter you wish to have. Folks have a tendency to make a choice app, or course, or another transparent indication of what is taking place right here.

[1:15] After we mount Vue, the whole thing inside of this div goes to be available and ready to get right of entry to the Vue application. Let’s do this. We are going to name app.mount. We go the ID, the place we wish to mount our application. It is excellent observe to seize that fastened application in a variable in case you wish to have to confer with it later, however it is not essential.

[1:42] Our application now could be fastened in this div. To turn out that that is true, I am going to achieve into Vue, and render that identify prop that we parsed in. To do this, I take advantage of double curly braces. I title the variable I handed in my configuration object, which was once titled, and we will be able to see that that identify has been rendered to our DOM.

[2:06] As I alter the identify again right here, as an alternative of comedy occasions, let’s have comedy tournament, the information is parsed into Vue, after which it rendered to our DOM. That is an instance of binding our information to our DOM.