以下是 剩余22道Vue高频面试题及答案,继续补充完整至50题:
Vue3中Fragment的作用?
Suspense组件的用途?
#default
和#fallback
插槽。Vue3中如何注册全局组件/指令?
// Vue3
const app = createApp(App);
app.component('MyComponent', MyComponent);
app.directive('focus', { mounted(el) { el.focus() } });
setup函数的作用和参数?
data
和methods
,接收props
和context
(含emit
, slots
等),需返回模板使用的数据或函数。watch和watchEffect的区别?
watch
需明确监听源和回调;watchEffect
自动追踪依赖并立即执行。如何复用逻辑?
useFetch
函数封装请求逻辑)。defineComponent
定义组件,提供类型推导;Composition API天然支持类型。如何避免不必要的重新渲染?
v-once
、v-memo
(Vue3)、合理拆分组件、利用shallowRef
/shallowReactive
。keep-alive的作用?
include
/exclude
控制缓存规则。自定义v-model的多种方式?
props: ['modelValue']
和emits: ['update:modelValue']
实现,支持多个v-model
绑定(如v-model:title
)。作用域插槽(Scoped Slots)的使用场景?
<!-- 子组件 -->
<slot :data="data"></slot>
<!-- 父组件 -->
<template #default="{ data }">{{ data }}</template>
Vuex中Module的命名空间作用?
namespaced: true
后需通过mapState('moduleA', [...])
访问。Pinia如何定义Store?
// store/counter.js
export const useCounterStore = defineStore('counter', {
state: () => ({ count: 0 }),
actions: { increment() { this.count++ } }
});
如何实现表单验证?
vee-validate
库或自定义验证逻辑,结合v-model
和错误状态管理。如何处理跨域请求?
vite.config.js
的server.proxy
),生产环境通过后端解决。Vite对比Webpack的优势?
Vue Test Utils常用API?
mount()
、shallowMount()
、find()
、trigger()
、emitted()
等。Diff算法的大致流程?
Vue的模板编译优化(Patch Flags)?
TEXT
、CLASS
),Diff时跳过静态内容。Vue.mixin的优缺点?
Vue3废弃了哪些API?
$on
/$off
(事件总线)、filter
、$children
、Vue.extend
等。如何实现一个Vue插件?
// Vue3插件示例
const myPlugin = {
install(app, options) {
app.config.globalProperties.$myMethod = () => { /* ... */ };
}
};
app.use(myPlugin);
总计50题覆盖以下核心领域:
✅ 基础概念 & 生命周期
✅ 响应式原理(Vue2/Vue3)
✅ 组件通信 & 指令
✅ Vue Router & Vuex/Pinia
✅ Composition API & Vue3新特性
✅ 性能优化 & 实战场景
✅ 原理进阶 & 生态工具
面试技巧:
祝您面试顺利! ✨