自定义指令

1.eg:全局注册自定义v-focus指令

Vue.directive('focus', {
bind() {},
inserted(el) {
el.focus()
},
update() {},
componentUpdated() {},
unbind() {}
})

2.使用v-focus指令

<template>
<input v-focus />
</template>

生命周期的理解

1)生命周期是什么?

Vue 实例有一个完整的生命周期,也就是从开始创建、初始化数据、编译模版、挂载 Dom -> 渲染、更新 -> 渲染、卸载等一系列过程,我们称这是 Vue 的生命周期。

2)各个生命周期的作用

![image-20230106135142037](../Library/Application Support/typora-user-images/image-20230106135142037.png)

1.png