10 Essential Vue.js Interview Questions *

Toptal sourced essential questions that the best Vue.js developers and engineers can answer. 在我们社区的推动下,我们鼓励专家提交问题并提供反馈.

Hire a Top Vue.js Developer Now
Toptal logois an exclusive network of the top freelance software developers, designers, finance experts, product managers, and project managers in the world. Top companies hire Toptal freelancers for their most important projects.

Interview Questions

1.

Explain the difference between slots and scoped slots.

View answer

槽是子组件中的占位符,由父组件传递的内容填充. 常规槽的内容在父组件的作用域中编译,然后传递给子组件.

Thus you can’t use child component properties in a slot’s content. But scoped slots 允许您将子组件数据传递给父作用域,然后在槽内容中使用该数据.

2.

Explain Vue.js reactivity and common issues when tracking changes.

View answer

All properties defined in a Vue instance’s data option are reactive这意味着如果它们发生变化,组件将自动更新并根据需要重新呈现.

在初始化期间,所有这些属性都转换为getter和setter, thus allowing Vue to detect when those properties are accessed or changed.

The following limitations must be accounted for when designing a Vue app:

  • 由于JavaScript的限制,我们无法检测对象属性的添加或删除 Vue.set method must be used to add new root-level reactive properties.
  • Similarly, Vue cannot detect when an array item is modified using an index. Vue.set must be used here as well.
3.

What are mixins? Describe their benefits and drawbacks.

View answer

Mixin支持是一个允许Vue中组件之间代码重用的特性.js application and a software composition tool.

mixin是一个JavaScript对象,它可以包含组件可以包含的任何选项. 当组件使用mixin时,所有的mixin内容都会与组件的选项合并.

Mixins help with following the DRY (don’t repeat yourself) principle. A mixin can even be applied globally to every component instance. In that case, it’s called a global mixin.

Mixins are a powerful tool, but some caution is needed while using them. 与所有注入代码一样,我们应该小心避免维护问题和意外行为.

它有助于使用纯函数来实现mixins,这些函数不修改自己作用域之外的任何东西.

Global mixins should be avoided, 随着应用程序的增长,影响每个组件可能会导致维护问题. 根据需要向组件中注入特定的mixins会带来更易于维护的代码.

Apply to Join Toptal's Development Network

and enjoy reliable, steady, remote Freelance Vue.js Developer Jobs

Apply as a Freelancer
4.

What is a single-file component?

View answer

A single-file component is a file with a .vue extension that contains a Vue component. 它将组件的模板、逻辑和样式都捆绑在一个文件中. It consists of one