码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • VueJS面试常见的300道题(英文版)


    VueJS面试常见的300道题
    List of 300 VueJS Interview Questions

    Table of Contents


    No.Questions
    1What is VueJS
    2What are the major features of VueJS
    3What are the lifecycle methods of VueJS
    4What are the conditional directives
    5What is the difference between v-show and v-if directives
    6What is the purpose of v-for directive?
    7What is vue instance?
    8How do you achieve conditional group of elements?
    9How do you reuse elements with key attribute?
    10Why should not use if and for directives together on the same element?
    11Why do you need to use key attribute on for directive?
    12What are the array detection mutation methods?
    13What are the array detection non mutation methods?
    14What are the caveats of array changes detection?
    15What are the caveats of object changes detection?
    16How do you use for directive with a range?
    17How do you use for directive on template?
    18How do you use event handlers?
    19What are the event modifiers provided by vue?
    20What are key modifiers?
    21How do you define custom key modifier aliases?
    22What are the supported System Modifier Keys?
    23What are the supported Mouse Button Modifiers?
    24How do you implement two way binding?
    25What are the supported modifiers on model?
    26What are components and give an example?
    27What are props?
    28When component needs a single root element?
    29How do you communicate from child to parent using events?
    30How do you implement model on custom input components?
    31What are slots?
    32What is global registration in components?
    33Why do you need local registration?
    34What is the difference between local and global registration in module system?
    35What are possible prop types?
    36What is the data flow followed by props?
    37What are non prop attributes?
    38Describe about validations available for props?
    39How do you customize model directive for a component?
    40What are the possible ways to provide transitions?
    41What is vue router and their features?
    42What are the steps to use vue router and give an example?
    43What is dynamic route matching?
    44How to make router param changes as reactive?
    45What is route matching priority?
    46What are nested routes?
    47What are single file components?
    48Is Single File Components violating separation of concerns?
    49What are the problems solved by Single File Components?
    50What are filters?
    51What are the different ways to create filters?
    52How do you chain filters
    53Is it possible to pass parameters for filters?
    54What are plugins and their various services?
    55 How to create a plugin?
    56How to use a plugin?
    57What are mixins?
    58What are global mixins?
    59How do you use mixins in CLI?
    60What are the merging strategies in mixins?
    61What are custom options merging strategies?
    62What are custom directives?
    63How do you register directives locally?
    64What are the hook functions provided by directives?
    65What are the directive Hook Arguments?
    66How do you pass multiple values to a directive?
    67What is function shorthand in directive hooks?
    68What is the benefit of render functions over templates?
    69What is a render function?
    70Explain the structure of createElement with arguments
    71How can you write duplicate virtual nodes in a component?
    72List down the template equivalents in render functions?
    73What are functional components?
    74What are the similarities between VueJS and ReactJS?
    75What is the difference between VueJS and ReactJS?
    76What are the advantages of VueJS over ReactJS?
    77What are the advantages of ReactJS over VueJS?
    78What are the differences between VueJS and Angular?
    79What are dynamic components?
    80What is the purpose of keep alive tag?
    81What are async components?
    82What is the structure of async component factory?
    83What are inline templates?
    84What are X Templates?
    85What are recursive components?
    86How do you resolve circular dependencies between components?
    87How do you make sure vue application is CSP complaint?
    88What is the difference between full and runtime only builds?
    89List down different builds of vuejs?
    90How do you configure vuejs in webpack?
    91What is the purpose of vuejs compiler?
    92What is Dev Tools and its purpose?
    93What is the browser support of VueJS?
    94How do you use various CDNs?
    95How do you force update?
    96What is the purpose of vuejs once directive?
    97How do you access the root instance?
    98List out top 10 organizations using Vuejs?
    99What is the purpose of renderError?
    100How do you access parent instance?
    101What is vuex?
    102What are the major components of State Management Pattern?
    103How do you represent one way data flow in vuex?
    104What is a vuejs loader?
    105How do you configure vue loader in webpack?
    106What are asset url transform rules?
    107How do you work with preprocessors using vue loader?
    108What is scoped CSS?
    109Is it possible to mix both local and global styles?
    110How do you use deep selectors?
    111Is parent styles leaked into child components in scoped css?
    112How do you style dynamic generated content using scoped css?
    113Is CSS modules supported in Vuejs?
    114Can I use runtime builds for all templates?
    115How to use CSS modules in vuejs?
    116Can I use CSS modules for preprocessors?
    117Is it possible to use custom inject name for CSS modules?
    118What is hot reloading in vue loader?
    119What is the default behavior of hot reloading?
    120How do you disable hot reloading explicitly?
    121How do you use hot reloading?
    122What are state preservation rules in hot reloading?
    123How to create functional components using vue loader?
    124How do you access global properties of functional components?
    125How do you perform testing in vuejs?
    126How do you apply linting for css?
    127How do you use eslint plugin?
    128What is the purpose of eslint loader?
    129What is CSS extraction?
    130What are custom blocks?
    131What are the features of stylelint?
    132What are the principles for vuex application structure?
    133Is Vuex supports hot reloading?
    134What is the purpose of hotUpdate API of vuex store?
    135How do you test mutations?
    136How do you test your getters?
    137What is the procedure to run tests in node?
    138What is the procedure to run tests in browser?
    139What is the purpose of strict mode in vuex?
    140Can I use strict mode in production environment?
    141What is vuex plugin?
    142How do you mutate state in plugins?
    143What is vuex store?
    144What are the differences of vuex store and plain global object?
    145What is the reason not to update the state directly?
    146What is Single state tree?
    147How do you install vuex?
    148Do I need promise for vuex?
    149How do you display store state in vue components?
    150How do you inject store into child components?
    151What is mapState helper?
    152How do you combine local computed properties with mapState helper?
    153Do you need to replace entire local state with vuex?
    154What are vuex getters?
    155What is a property style access?
    156What is a method style access?
    157What is mapGetter helper?
    158What are mutations?
    159How do you commit with payload?
    160What is object style commit?
    161What are the caveats with vuex mutations?
    162Why mutations should be synchronous?
    163How do you perform mutations in components?
    164Is it mandatory to use constants for mutation types?
    165How do you perform asynchronous operations?
    166What are differences between mutations and actions?
    167Give an example usage of actions?
    168How do you dispatch actions?
    169Can you dispatch an action using payload or object?
    170Can I use styled components in vuejs?
    171How do you dispatch actions in components?
    172How do you compose actions?
    173What are modules in vuex?
    174What is module local state?
    175What is namespacing in vuex
    176What is the default namespace behavior in vuex?
    177When do you reuse modules?
    178What are the principles enforced by vuex?
    179Can I perform mutations directly in strict mode?
    180How to use model directive with two way computed property?
    181What is Vue CLI?
    182What are the features provided by Vue CLI?
    183What is instant prototyping?
    184How do you create project using Vue CLI?
    185How do you create project using GUI?
    186What are plugins in vue CLI?
    187How do you install plugins in an existing Vue CLI project?
    188How to access local plugins in a project?
    189How do you create UI plugins kind of behavior?
    190What are presets?
    191What is the versioning behavior in preset plugins?
    192How do you allow plugin prompts?
    193What are remote presets?
    194Can I use local presets?
    195What is the purpose of browserslist option?
    196How do you find VueJS version using API?
    197How do you create reactive objects
    198What is the purpose new slot directive?
    199What is the use of compile method?
    200What does nextTick do in VueJS?
    201What is async error handling?
    202What are Dynamic Directive Arguments?
    203What are the drawbacks of dynamic directive arguments?
    204What is the special handling for null values in dynamic directive arguments?
    205Can I use dynamic directive null value for slots?
    206What is Vue I18n plugin?
    207#What are the types of formatting?
    208What is custom formatting?
    209How do you handle Pluralization?
    210How to implement DateTime localization?
    211How do you implement Number localization?
    212How do you perform locale changing
    213What is Lazy loading translations?
    214What is the main difference between method and computed property?
    215What is vuetify?
    216How do you watch for nested data changes?
    217How to trigger watchers on initialization?
    218What is the purpose of comments option?
    219How to identify whether code is running on client or server?
    220How do you watch route object changes?
    221How do you sync current route in vuex store?
    222What are navigation guards in vue router?
    223Can I use computed property in another computed property?
    224How can I use imported constant in template section?
    225Is recommended to use async for computed properties?
    226What happens if you use duplicate field names?
    227Why the component data must be a function?
    228What is the reason for recommendation for multi-word component names?
    229How to use composition API in Vue2.0?
    230What is composition API?
    231What is the best way to re-render a component?
    1. What is VueJS?

      Vue.js is an open-source, progressive Javascript framework for building user interfaces that aim to be incrementally adoptable. The core library of VueJS is focused on the view layer only, and is easy to pick up and integrate with other libraries or existing projects.

      ⬆ Back to Top

    2. What are the major features of VueJS?

      Below are the some of major features available with VueJS

      1. Virtual DOM: It uses virtual DOM similar to other existing frameworks such as ReactJS, Ember etc. Virtual DOM is a light-weight in-memory tree representation of the original HTML DOM and updated without affecting the original DOM.
      2. Components: Used to create reusable custom elements in VueJS applications.
      3. Templates: VueJS provides HTML based templates that bind the DOM with the Vue instance data
      4. Routing: Navigation between pages is achieved through vue-router
      5. Light weight: VueJS is light weight library compared to other frameworks.

      ⬆ Back to Top

    3. What are the lifecycle methods of VueJS?

      Lifecycle hooks are a window into how the library you’re using works behind-the-scenes. By using these hooks, you will know when your component is created, added to the DOM, updated, or destroyed. Let’s look at lifecycle diagram before going to each lifecycle hook in detail,

      1. Creation(Initialization):
        Creation Hooks allow you to perform actions before your component has even been added to the DOM. You need to use these hooks if you need to set things up in your component both during client rendering and server rendering. Unlike other hooks, creation hooks are also run during server-side rendering.
        1. beforeCreate:
          This hook runs at the very initialization of your component. hook observes data and initialization events in your component. Here, data is still not reactive and events that occur during the component’s lifecycle have not been set up yet.
            new Vue({
              data: {
               count: 10
              },
              beforeCreate: function () {
                console.log('Nothing gets called at this moment')
                // `this` points to the view model instance
                console.log('count is ' + this.count);
              }
            })
               // count is undefined
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        1. created:
          This hook is invoked when Vue has set up events and data observation. Here, events are active and access to reactive data is enabled though templates have not yet been mounted or rendered.
          new Vue({
            data: {
             count: 10
            },
            created: function () {
              // `this` points to the view model instance
              console.log('count is: ' + this.count)
            }
          })
             // count is: 10
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        Note: Remember that, You will not have access to the DOM or the target mounting element (this.$el) inside of creation hooks
      2. Mounting(DOM Insertion):
        Mounting hooks are often the most-used hooks and they allow you to access your component immediately before and after the first render.
        1. beforeMount:
          The beforeMount allows you to access your component immediately before and after the first render.
          new Vue({
            beforeMount: function () {
              // `this` points to the view model instance
              console.log(`this.$el is yet to be created`);
            }
          })
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        1. mounted:
          This is a most used hook and you will have full access to the reactive component, templates, and rendered DOM (via. this.$el). The most frequently used patterns are fetching data for your component.
        <div id="app">
            <p>I’m text inside the component.</p>
        </div>
          new Vue({
            el: ‘#app’,
            mounted: function() {
              console.log(this.$el.textContent); // I'm text inside the component.
            }
          })
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
      3. Updating (Diff & Re-render):
        Updating hooks are called whenever a reactive property used by your component changes, or something else causes it to re-render
        1. beforeUpdate:
          The beforeUpdate hook runs after data changes on your component and the update cycle begins, right before the DOM is patched and re-rendered.
        <div id="app">
          <p>{{counter}}</p>
        </div>
        ...// rest of the code
          new Vue({
            el: '#app',
            data() {
              return {
                counter: 0
              }
            },
             created: function() {
              setInterval(() => {
                this.counter++
              }, 1000)
            },
        
            beforeUpdate: function() {
              console.log(this.counter) // Logs the counter value every second, before the DOM updates.
            }
          })
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
        • 13
        • 14
        • 15
        • 16
        • 17
        • 18
        • 19
        • 20
        • 21
        1. updated:
          This hook runs after data changes on your component and the DOM re-renders.
        <div id="app">
          <p ref="dom">{{counter}}</p>
        </div>
        ...//
          new Vue({
            el: '#app',
            data() {
              return {
                counter: 0
              }
            },
             created: function() {
              setInterval(() => {
                this.counter++
              }, 1000)
            },
            updated: function() {
              console.log(+this.$refs['dom'].textContent === this.counter) // Logs true every second
            }
          })
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
        • 13
        • 14
        • 15
        • 16
        • 17
        • 18
        • 19
        • 20
      4. Destruction (Teardown):
        Destruction hooks allow you to perform actions when your component is destroyed, such as cleanup or analytics sending.
        1. beforeDestroy:
          beforeDestroy is fired right before teardown. If you need to cleanup events or reactive subscriptions, beforeDestroy would probably be the time to do it. Your component will still be fully present and functional.
        new Vue ({
          data() {
            return {
              message: 'Welcome VueJS developers'
            }
          },
        
          beforeDestroy: function() {
            this.message = null
            delete this.message
          }
        })
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
        1. destroyed:
          This hooks is called after your component has been destroyed, its directives have been unbound and its event listeners have been removed.
        new Vue ({
            destroyed: function() {
              console.log(this) // Nothing to show here
            }
          })
        
        • 1
        • 2
        • 3
        • 4
        • 5

      ⬆ Back to Top

    4. What are the conditional directives?

      VueJS provides set of directives to show or hide elements based on conditions. The available directives are: v-if, v-else, v-else-if and v-show

      1. v-if: The v-if directive adds or removes DOM elements based on the given expression. For example, the below button will not show if isLoggedIn is set to false.

      <button v-if="isLoggedIn">Logout</button>
      
      • 1

      You can also control multiple elements with a single v-if statement by wrapping all the elements in a