1.创建App 实例并挂载
(directive相关,
plugin相关)
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
app.config = {}
app.component(‘全局组件名’, 定义的组件)
app.directive('自定义指令名', 指令方法体)
app.use(plugins)
app.mount('#app')
app.config.errorHandler
app.config.warnHandler
app.config.globalProperties
app.config.globalProperties.xxx = 'xxxx'
app.config.globalProperties.fn = {
fn1:()=>{}
}
app.config.optionMergeStrategies
const app = createApp({
mounted() {
console.log(this.$options.hello)
}
})
app.config.optionMergeStrategies.hello = (parent, child) => {
return Hello, ${ child }
}
app.mixin({ hello: 'Vue' })
3.模板语法:(基本同vue2,跳过)
ref全家桶相关
reactive相关
reactive 底层简单实现
toRaw相关
7. vue3的生命周期执行
setup(props, context) {} 组件创建之前执行(初始化 data 和 methods 方法),早于beforeCreate() created()
onBeforeMount(() => {
console.log('onBeforeMount')
})
onMounted(() => {
console.log('onMounted')
})
onBeforeUpdate(() => {
console.log('onBeforeUpdate')
})
onUpdated(() => {
console.log('onUpdated')
})
onActivated(() => {
console.log('onActivated')
})
8.异步组件的使用
import { defineAsyncComponent } from 'vue'
const AsyncCompLyon = defineAsyncComponent(() =>
import('./components/Lyon.vue')
)
<template> <AsyncCompLyon /> </template>
9.# 内置组件 Teleport dom传送门
const num = ref(1)
const box = ref('#box1')
const clickBtn = function() {
num.value = Math.ceil(Math.random()*3)
box.value = `#box${num.value}`
}
<div id="box1"></div>
<div id="box2"></div>
<div id="box3"></div>
<!-- 传送到某个dom 节点 -->
<Teleport :to='box'>
<div>teleport</div>
</Teleport>
<button @click= "clickBtn">传送到{{box}}</button>
<style lang="scss" scoped>
#box1 {
height: 100px;
border: 1px solid red;
}
#box2 {
height: 100px;
border: 1px solid blue;
}
#box3 {
height: 100px;
border: 1px solid pink;
}
</style>
# 实验内置组件 Suspense 异步依赖树渲染(跳过)
9. 常用的工具函数
console.log(isProxy(srt))
console.log(isRef(num))
console.log(isReactive(rt))
10. provide | inject 依赖注入(基本同vue2)
11. mixins 同vue2
import {h} from 'vue'
h: () => App