Table of Contents
vue interview questions
vue interview question analysis
Home Web Front-end Vue.js 13 front-end Vue interview questions to share (with answer analysis)

13 front-end Vue interview questions to share (with answer analysis)

Apr 12, 2021 pm 06:51 PM
vue front end

This article will share with you some front-end vue interview questions. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

13 front-end Vue interview questions to share (with answer analysis)

vue interview questions

1.How vue-router passes parameters
2.v- Disadvantages and solutions of using if and v-for together
3.What operations are generally performed in beforeDestroyed
4.How to transfer values ​​​​between components of the same level in vue
5.How do parent components in vue obtain child components? Properties and methods
6.The difference between watch and computed
7.The order of the life cycle of parent component and child component in vue
8.Can the parent component in vue monitor the life cycle of the child component
9. What are the main event modifiers in Vue? What are their respective functions
10. Introduce what is
11.Can watch monitor the pop behavior of the array?
12.How does watch implement deep monitoring
13. How to solve the problem of page not re-rendering in vue
(Learning video sharing: vue video tutorial)

vue interview question analysis

1. vue-router has two ways to pass parameters

(1) Dynamically pass parameters eg by configuring the path in the router.js file: path: ' /detail/:id' and then pass this.$route.params.id in the component to get

(2). Pass the parameter

<router-link :to={
params: {
	x: 1
	}
} />
Copy after login

in the router-link tag and also pass this .$route.params gets

Note: The way to pass parameters through router-link here is to pass parameters implicitly

2, v-if and v Disadvantages and solutions of using -for together

Since v-for has a higher priority than v-if, v-if will be visited every time the loop is passed, and v-if is passed Create and destroy DOM elements to control the display and hiding of elements, so elements will be constantly created and destroyed, causing page lag and performance degradation.

Solution: Use v-if by wrapping an element in the outer or inner layer of v-for

3. What operations are generally performed in beforeDestroy

beforedestoryed is a life cycle executed before the component is destroyed. In this life cycle, we can clear callback functions or timers, clear unused dom elements, etc.

4, vue How to transfer values ​​between components at the same level

1. If it is a sibling component, the value can be transferred through the parent element as an intermediate component 2. By creating a bus, the value can be transferred

// 创建一个文件,定义bus中间件,并导出
const bus = new Vue()
// 在一个组件中发送事件
bus.$emit(&#39;事件名称&#39;, 传递的参数)
// 在另一个组件中监听事件
bus.$on(&#39;事件名称&#39;, 得到传过来的参数)
Copy after login

5. How does the parent component in vue obtain the properties and methods of the subcomponent

Vue obtains the properties and methods of the subcomponent by defining the ref attribute on the subcomponent. The code is as follows:

// 这里是父组件
<templete>
	<child ref="child"/>
</templete>
<script>
method: {
	getChild () {
		this.$refs.child.属性名(方法名)
	}
}
</script>
Copy after login

6. The difference between watch and computed

The function of watch is usually that one value affects the changes of multiple values ​​and when it can monitor the change of this value, it will execute a Callback function, at this time we can do some logical processing in this callback function

computed is to derive a new value based on the dependent value, and there can be multiple dependent values, only when the dependent value When changes occur, the calculation will be re-executed

[Related recommendations: vue.js tutorial]

7. The life cycle of vue parent components and child components Sequence

1), rendering process sequence:

parent component beforeCreate() -> parent component created() -> parent component beforeMount() -> child component beforeCreate () ->Subcomponent created() -> Subcomponent beforeMount() -> Subcomponent mounted() -> Parent component mounted()

2), update process sequence:

Update process of parent component:
Parent component beforeUpdate() -> Parent component updated()

Update process of child component:
Parent component beforeUpdate() -> Child component beforeUpdate( ) -> Child component updated() -> Parent component updated()

3), destruction process
Parent component beforeDestroy() -> Child component beforeDestroy() -> Child component destroyed () -> Parent component destroyed()

8. Can the parent component in Vue monitor the life cycle of the child component?

Can the parent component monitor the child component? The life cycle of the monitoring code through @hook: is as follows:

// 这里是父组件
<template>
	<child
	@hook:mounted="getChildMounted"
	/>
</template>
<script>
method: {
	getChildMounted () {
		// 这里可以获取到子组件mounted的信息
	}
}
</script>
Copy after login

9. What are the main event modifiers in vue? What are the functions?

.stop: prevent events from bubbling
.native: bind native events
.once: events are executed only once
.self: bind events On itself, it is equivalent to preventing events from bubbling
.prevent: Preventing default events
.caption: Used for event capture

10. Introduce what is keep-alive

keep-alive is used for component caching. It will only be executed once and will not be destroyed. Components wrapped by keep-alive do not have methods such as create and beforeDestroyed, but they have activated and deactivated methods.

11. Can the watch monitor the pop behavior of the array?

对于有返回值的数据,watch就能监听到,比如数组的pop,push, unshift,map等行为。

12、watch如何实现深度监听

watch: {
	obj: {
		handler: function(val) {
		},
		deep: true // 深度监听
	}
}
Copy after login

13、vue中如何解决页面不重新渲染问题

(1).修改对象属性后页面未重新渲染可以使用 this.$set(对象名称, '属性名', '属性值') (2).使用this.$forceUpdate()方法可重新渲染页面

更多编程相关知识,请访问:编程视频!!

The above is the detailed content of 13 front-end Vue interview questions to share (with answer analysis). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add functions to buttons for vue How to add functions to buttons for vue Apr 08, 2025 am 08:51 AM

You can add a function to the Vue button by binding the button in the HTML template to a method. Define the method and write function logic in the Vue instance.

How to reference js file with vue.js How to reference js file with vue.js Apr 07, 2025 pm 11:27 PM

There are three ways to refer to JS files in Vue.js: directly specify the path using the &lt;script&gt; tag;; dynamic import using the mounted() lifecycle hook; and importing through the Vuex state management library.

How to use watch in vue How to use watch in vue Apr 07, 2025 pm 11:36 PM

The watch option in Vue.js allows developers to listen for changes in specific data. When the data changes, watch triggers a callback function to perform update views or other tasks. Its configuration options include immediate, which specifies whether to execute a callback immediately, and deep, which specifies whether to recursively listen to changes to objects or arrays.

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

How to return to previous page by vue How to return to previous page by vue Apr 07, 2025 pm 11:30 PM

Vue.js has four methods to return to the previous page: $router.go(-1)$router.back() uses &lt;router-link to=&quot;/&quot; component window.history.back(), and the method selection depends on the scene.

Vue realizes marquee/text scrolling effect Vue realizes marquee/text scrolling effect Apr 07, 2025 pm 10:51 PM

Implement marquee/text scrolling effects in Vue, using CSS animations or third-party libraries. This article introduces how to use CSS animation: create scroll text and wrap text with &lt;div&gt;. Define CSS animations and set overflow: hidden, width, and animation. Define keyframes, set transform: translateX() at the beginning and end of the animation. Adjust animation properties such as duration, scroll speed, and direction.

How to query the version of vue How to query the version of vue Apr 07, 2025 pm 11:24 PM

You can query the Vue version by using Vue Devtools to view the Vue tab in the browser's console. Use npm to run the "npm list -g vue" command. Find the Vue item in the "dependencies" object of the package.json file. For Vue CLI projects, run the "vue --version" command. Check the version information in the &lt;script&gt; tag in the HTML file that refers to the Vue file.

How to use function intercept vue How to use function intercept vue Apr 08, 2025 am 06:51 AM

Function interception in Vue is a technique used to limit the number of times a function is called within a specified time period and prevent performance problems. The implementation method is: import the lodash library: import { debounce } from 'lodash'; Use the debounce function to create an intercept function: const debouncedFunction = debounce(() =&gt; { / Logical / }, 500); Call the intercept function, and the control function is called at most once in 500 milliseconds.

See all articles