Vue.js Flashcards
What are the 5 steps to initializing a Vue web application?
- Install vue-cli globally with: npm install -g vue-cli
- Initialize the project from a template with: vue init
- Change directory: cd
- Install dependencies: npm install
- Run in development mode: npm run dev
What command is used to start the application in development mode?
npm run dev
What commands are used to run the application for production?
npm run build
npm run start
Name all of the Vue lifecycle hooks
created
mounted
updated
destroyed
What are lifecycle hooks in Vue?
Lifecycle hooks are the defined methods which get executed in a certain stage of the Vue object lifespan
In Nuxt.js, how would you pull data from an API call to use when a component is created?
Use an async created() lifecycle hook with axios to make the API call
In Vue.js, what does @submit.prevent do?
It prevents the default behavior of a submit button when it is clicked (the way that preventDefault() does in JavaScript to an event)
What is the syntax for an “emit” statement in Vue.js?
this.$emit(‘var-name’, this.varName);
In Vue.js, what do you need to do in a parent template in order to receive an emitted variable?
add an event listener with the following syntax:
“ComponentName @emitted-var-name=”receivingMethod” /”
Then, create the receiving method:
receivingMethod(varName) {
this.parentVar = varName;
}
In Vue.js, which directive is used in order to make a two–way data binding connection between an element and a variable in the data()?
v-model