DEV Community

Cover image for Interview Questions for Vue
Adnan Babakan (he/him)
Adnan Babakan (he/him)

Posted on • Edited on

Interview Questions for Vue

Hey there Dev.to community!

I've been a Vue fan for a long time, even before time itself. Here are some questions I've had the experience of being asked while in an interview. Something to be clear first, don't ever look at an interview as an interview! Just have fun and be yourself. Answer things you know and honestly answer No if you don't. If you get into a job with cheating or lying, you won't be happy there and you might also get in trouble. So study hard, but don't push it too hard.

Some questions might not be exclusive to Vue, and they might be general questions that can apply to other frameworks or tools as well.

The questions aren't ordered in any category (being hard to easy or anything).

Some code samples are from Vue's Official Documentation.

What is SPA?

SPA stands for Single Page Application. A SPA is an application that downloads the layout first and by moving between pages it won't need to get the whole page again and won't refresh the whole page. Instead, it will retrieve the necessary parts from the server and replace its content on the page.

What are Vue directives?

Vue directives are simply HTML attributes used by Vue to extend the functionality of Vue. Like:

  • v-if, v-else
  • v-show
  • v-model
  • v-on

What is two-way binding?

Two-way binding in Vue refers to the ability of Vue to update the input value and the data stored in your Vue script. This is usually done by the v-model directive.

<template>
    <div>
        <input type="text" v-model="message" /><br>
        Your message: {{ message }}
    </div>
</template>

<script>
  export default {
    data() {
      return {
        message: ''
      }
    }
  }
</script>
Enter fullscreen mode Exit fullscreen mode

What is Virtual DOM (VDOM)?

This is a scary question on the surface, but the answer is quite simple. Virtual DOM is a JavaScript object that holds your UI (document) and syncs its changes with the actual DOM (your real UI) when needed or told to do so. This makes the page much faster since updating DOM every once is a high-cost operation.

What is Vue SFC?

SFC refers to Single File Component feature of Vue. A Vue component can be a simple object as below:

Vue.component('button-counter', {
    data: function() {
      return {
        count: 0
      }
    },
    template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
  })
Enter fullscreen mode Exit fullscreen mode

Or for more complex applications you can put every component in file with .vue extension and import it when needed. This file looks like this:

<template>
    <div>

    </div>
</template>

<script>
  export default {

  }
</script>

<style scoped>

</style>
Enter fullscreen mode Exit fullscreen mode

A Vue SFC can hold components template (usually HTML), script and style. This feature helps you organize your application better.

What is Vue life-cycle?

The life-cycle term refers to the way Vue gets to run and some of the function that it calls in order to let the programmer choose when to run some functionalities of their program. The picture below helps you a lot in this matter:

Vue life-cycle

How would you import data from the back-end to your Vue application?

The main idea of designing a front-end application is to let users interact with the data you have, so importing them are crucial. There are several ways of importing data to a Vue application but two are really common:

  • Putting data in your back-end template and send it along
  • AJAX call

The first one is discouraged since it can cause conflicts. Making an AJAX call is much easier and is actually a more standard way. To make an AJAX call, you can use JavaScript's built-in fetch function and for more advanced features you can use axios which is a third-party library.

What are watchers in Vue?

Watchers are functions that run when specific data is changed.

  export default {
    data() {
      return {
        message: ''
      }
    },
    watch: {
      message() {
        console.log('Message got changed!')
      }
    }
  }
Enter fullscreen mode Exit fullscreen mode

What are computed properties in Vue?

A computed property is as a data field which is a function of another data field:

  export default {
    data() {
      return {
        username: 'Adnan'
      }
    },
    computed: {
      welcome() {
        return 'Welcome ' + this.user
      }
    }
  }
Enter fullscreen mode Exit fullscreen mode

Now welcome is equal to Welcome Adnan and can be used as a data property like {{ welcome }}.

What is routing in Vue?

Routing in Vue means separating your application into multiple pages and assigning each page to a component. Vue routing is done by Vue Router which is an official library designed by Vue team.

What are the filters in Vue?

Filters are used to manipulate data when rendering. Like capitalizing.

A filter is indicated after a pipe (vertical bar) sign:

<template>
    <div>
            {{ message | capitalize }}
    </div>
</template>
Enter fullscreen mode Exit fullscreen mode

Filters are also available in bindings:

<template>
    <div>
            <div :id="myId | capitalize"></div>
    </div>
</template>
Enter fullscreen mode Exit fullscreen mode

How to create custom filters?

A filter can be defined both globally (which can be accessed throughout the Vue application, or locally only for a component.

Globally:

Vue.filter('capitalize', function(value) {
    if (!value) return ''
    value = value.toString()
    return value.charAt(0).toUpperCase() + value.slice(1)
  })
Enter fullscreen mode Exit fullscreen mode

Component:

filters: {
    capitalize: function(value) {
      if (!value) return ''
      value = value.toString()
      return value.charAt(0).toUpperCase() + value.slice(1)
    }
  }
Enter fullscreen mode Exit fullscreen mode

What is Vue mixin?

Mixins are objects that can extend your current component. This can help you share functionality between your components.

// define a mixin object
  var myMixin = {
    created: function() {
      this.hello()
    },
    methods: {
      hello: function() {
        console.log('hello from mixin!')
      }
    }
  }

  // define a component that uses this mixin
  var Component = Vue.extend({
    mixins: [myMixin]
  })

  var component = new Component() // => "hello from mixin!"
Enter fullscreen mode Exit fullscreen mode

What is Vuex?

Vuex is a state management library. It helps you organize your states in a way it is meant to be and reducing the risk of data being altered in a way that's not secure.


Check out my free Node.js Essentials E-book here:

Top comments (11)

Collapse
 
kushal-niroula profile image
Kushal Niroula

It's worth noting that Filters have been removed in Vue 3.

It is advised to use a regular method call or computed property to achieve its task.

Your example would then become,

{
...,
computed: {
    capitalizedValue: function() {
      if (!this.value) return '';
      return this.value.charAt(0).toUpperCase() + this.value.slice(1);
    }
  },
methods: {
    capitalize: function(value) {
      if (!value) return '';
      value = value.toString()
      return value.charAt(0).toUpperCase() + value.slice(1)
    }
}
...
Enter fullscreen mode Exit fullscreen mode
<div>
{{ capitalizedValue }}

{{ capitalize(value) }}
</div>
Enter fullscreen mode Exit fullscreen mode

Read more about it and the migration strategy here v3.vuejs.org/guide/migration/filte...

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Thanks for reading my article. Yes, I am aware of this change but Vue 3 isn't officially out yet and the current official version is 2. So I omitted Vue 3 related things.

Collapse
 
crisarji profile image
crisarji

Nice article!, 2 things:

  1. VDOM: the shallow answer is ok, but for an interview, explaining the cycle and the difference with the DOM gives extra points!.
  2. What are computer properties in Vue? => mistype, "computed", I guess?.
Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Hi, thanks for reading my article. You are right about number one and thanks for spotting the typo!

Collapse
 
nathandj91 profile image
Nathan DJ

Great article.

Is it worth adding a few Vue 3 questions?

E.g. What is the composition API?

Or even adding something regarding the drawbacks and benefits of render functions vs SFC

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Hi, thanks for reading my article. I also thought of adding this question but since Vue 3 is still not the officially released version I think this question wouldn't fit in an interview.

Collapse
 
nathandj91 profile image
Nathan DJ

Vue 3 was officially released as of 18th September 2020.

There are still a couple of issues, mainly with DevTools and IE support.

If you've updated the CLI and created a new project, it now defaults to Vue 3.

Thread Thread
 
adnanbabakan profile image
Adnan Babakan (he/him)

Yes Vue 3 is released. But the main website still documents Vue 2 by default. So the major version in use is still Vue 2.

Collapse
 
ngthuongdoan profile image
Doan Ngoc Thuong

Great! I want to suggest one more question. Compare Vue with other frameworks and libraries? vuejs.org/v2/guide/comparison.html

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Thanks for reading my article. I don't think comparing two frameworks in performance or other ways would be a good question in an interview. At least I've never encountered one XD.

Collapse
 
ngthuongdoan profile image
Doan Ngoc Thuong

Hmm maybe the better question is "Why Vue? Why did you choose it?"