一、🖇框架搭建
1、关于文档
首先附上官方文档的具体材料:cn.vuejs.org/api/
2、VUE3 API整体盘点
在vue3的全新API中,有部分在vue2的基础上沿用了。还有另外一部分,是vue3所新增加的。我们先来看vue3 API文档主要包含哪些内容?
vue3 API主要包含以下六个部分:
全局API —— 全局会用到的API
组合式API —— vue3所拥有的组合式API
选项式API —— vue2所拥有的选项式API
内置内容 —— 指令、组件、特殊元素和特殊属性
单文件组件 —— 语法定义、
进阶API —— 渲染函数、服务端渲染、TS工具类型和自定义渲染
![](https://img-blog.csdnimg.cn/img_convert/5634f0ff3f10407224c7b336c1252496.webp?x-oss-process=image/format,png)
下面将依据上面提到的六大点内容,来进行相应的剖析和讲解。
二、🎨全局API
vue3的全局API包含两个部分:应用实例和通用API。那它们各自都有哪些内容呢?
1、应用实例
![](https://img-blog.csdnimg.cn/img_convert/e697c49f57938368af0e19ae78be8eff.webp?x-oss-process=image/format,png)
2、通用API
![](https://img-blog.csdnimg.cn/img_convert/3f693aae63477395fe897785e1a9eafb.webp?x-oss-process=image/format,png)
三、🚲组合式API
谈到vue3 ,相信大家最为熟悉的就是 composition API 了,也就是 组合式 API 。那么,vue3 的 组合式 API 都给我们带来了什么呢?
1、setup
![](https://img-blog.csdnimg.cn/img_convert/f75facb0c9f8a7d8337882efbcd9843f.webp?x-oss-process=image/format,png)
2、响应式:核心
![](https://img-blog.csdnimg.cn/img_convert/8a81c35dee42b1920be0ce3663de06aa.webp?x-oss-process=image/format,png)
3、响应式:工具函数
![](https://img-blog.csdnimg.cn/img_convert/82b7841240ea875bc9484f4ddb664fda.webp?x-oss-process=image/format,png)
4、响应式:进阶
![](https://img-blog.csdnimg.cn/img_convert/22ff98084576356f24e85038b3a74332.webp?x-oss-process=image/format,png)
5、生命周期钩子
![](https://img-blog.csdnimg.cn/img_convert/c27c2a34c0355a04ca73dabff00eb13e.webp?x-oss-process=image/format,png)
6、依赖注入
![](https://img-blog.csdnimg.cn/img_convert/d8d87e62b8972a966ca156667a24fb9d.webp?x-oss-process=image/format,png)
四、🌠选项式API
选项式API 即 options API 。可能有的小伙伴会觉得它在 vue2 项目下会更为常见一些。但在 vue3 项目中,也是有一些 选项式API 值得我们去挖掘的。那都有哪些内容呢,我们来一探究竟。
1、状态选项
![](https://img-blog.csdnimg.cn/img_convert/a346ae07806da23092161d803b2c167c.webp?x-oss-process=image/format,png)
2、渲染选项
![](https://img-blog.csdnimg.cn/img_convert/cd22df95761ad84995cbfa3be002cb38.webp?x-oss-process=image/format,png)
3、生命周期选项
![](https://img-blog.csdnimg.cn/img_convert/727ae163629a08e3fb70836d99be0152.webp?x-oss-process=image/format,png)
4、组合选项
![](https://img-blog.csdnimg.cn/img_convert/b22908716aecbbab0cd9a0f5e6bb673d.webp?x-oss-process=image/format,png)
5、其他杂项
![](https://img-blog.csdnimg.cn/img_convert/6416a0befb45430e79da44b7ffda7e05.webp?x-oss-process=image/format,png)
6、组件实例
![](https://img-blog.csdnimg.cn/img_convert/e389da54145afc3ac2eae4fbbfff5f66.webp?x-oss-process=image/format,png)
五、🏕内置内容
vue3 的内置内容包括指令、组件、特殊元素element和特殊属性attributes。如果要谈在什么场景下会用到内置内容,那周一可能觉得,在一般的 vue 项目开发中,基本都会用到内置内容。较为常见的是用v-if和v-else-if来判断什么时候显示某个组件,什么时候不显示某个组件。
还有像 v-model 、v-on 和 v-for 等指令,都是在 vue 项目中非常高频率使用的指令。那 vue3 的内置内容都还有哪些东西呢?请看下方介绍。
1、指令
![](https://img-blog.csdnimg.cn/img_convert/f4b865722435beb378303ad6dcae8a5b.webp?x-oss-process=image/format,png)
2、组件
![](https://img-blog.csdnimg.cn/img_convert/5c0212d666bd17118ff874c4a1528eb5.webp?x-oss-process=image/format,png)
3、特殊元素
![](https://img-blog.csdnimg.cn/img_convert/fb4474b46f0b6afb0c0052246dc7f3a2.webp?x-oss-process=image/format,png)
4、特殊属性Attributes
![](https://img-blog.csdnimg.cn/img_convert/2f5bb08c1f0127d2bc77546f8c486c67.webp?x-oss-process=image/format,png)
六、📸单文件组件
对于 vue 来说,相信大家都会非常熟悉它的组件化思想,似乎有一种理念是:万物皆可组件。那对于一个组件来说,我们都需要了解它的什么内容呢?比如,我们写的 <template> 是什么,用 <script setup> 和 <script lang="ts"> 都分别是什么含义,<style> 用了 scoped 是什么意思,:slotted 插槽选择器又在什么情况下使用呢?我们一起来一探究竟。
1、SFC语法定义
![](https://img-blog.csdnimg.cn/img_convert/91e421b56580261595f6d3dbcad93ed5.webp?x-oss-process=image/format,png)
2、单文件组件script setup
![](https://img-blog.csdnimg.cn/img_convert/5eff0c04ca9a18e106cef3ee5d10c7bc.webp?x-oss-process=image/format,png)
3、css功能
![](https://img-blog.csdnimg.cn/img_convert/654c7c502889886cc59ab7d7cabcfd12.webp?x-oss-process=image/format,png)
七、📈进阶API
上面我们了解了 vue3 的基础API,准确来说,上面的 API 可以解决实际工作中 80% 的问题。那下面,我们就再来看一些较为进阶的 api 操作。下面所涉及到的这些 API ,更多的是可以在某些定制化的场景下,做一些高阶的操作。比如:我们可以在一个 headless 组件里,用 render 和 h() 函数,来渲染自定义的页面。那 进阶 API 都还有哪些东西呢,来看下面的内容。
1、渲染函数
![](https://img-blog.csdnimg.cn/img_convert/b807ff32183d5f1c7c63ff3a05b737b9.webp?x-oss-process=image/format,png)
2、服务端渲染
![](https://img-blog.csdnimg.cn/img_convert/2998c84f9a4bddafdb0e81c2a8af70bc.webp?x-oss-process=image/format,png)
3、TypeScript工具类型
![](https://img-blog.csdnimg.cn/img_convert/e440ab57d62b0668225560774fdc5896.webp?x-oss-process=image/format,png)
4、自定义渲染
![](https://img-blog.csdnimg.cn/img_convert/d7555739b3db898da6228643ad3624c1.webp?x-oss-process=image/format,png)