博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Vue生命周期-父子组件生命周期加载顺序
阅读量:3918 次
发布时间:2019-05-23

本文共 1883 字,大约阅读时间需要 6 分钟。

1.在beforeCreate里调用method里的方法编辑器会有下图提示:

在这里插入图片描述
并且控制台报类型错误:
在这里插入图片描述
2.Vue中父子组件生命周期加载顺序:
情况一:子组件的更新在父组件之前的,有以下几种父子组件生命周期的组合
在这里插入图片描述
(1)调用异步方法改变数据和视图都在是父组件和子组件的created里

created () {
console.log('父组件的created') this.loadCourses()},created () {
console.log('子组件的created') this.loadCourses()},

(2)调用异步方法改变数据和视图,父组件的在beforeMount里调用,子组件的在created 里调用

beforeMount () {
console.log('父组件的beforeMount') this.loadCourses()},created () {
console.log('子组件的created') this.loadCourses()},

(3)调用异步方法改变数据和视图,父组件的在created 里调用,子组件的在beforeMount里调用

created () {
console.log('父组件的created' ) this.loadCourses()},beforeMount() {
console.log('子组件的beforeMount') this.loadCourses()},

(4)调用异步方法改变数据和视图都在是父组件和子组件的mounted里

mounted() {
console.log('父组件的mounted') this.loadCourses()},mounted() {
console.log('子组件的mounted') this.loadCourses()},

(5)调用异步方法改变数据和视图,父组件的在created 里调用,子组件的在mounted 里调用

created () {
console.log('父组件的created' ) this.loadCourses()},mounted () {
console.log('子组件的mounted ') this.loadCourses()},

(6)调用异步方法改变数据和视图,父组件的在mounted 里调用,子组件的在created里调用

mounted () {
console.log('父组件的mounted' ) this.loadCourses()},created() {
console.log('子组件的created') this.loadCourses()},

情况二:父组件的更新在子组件之前的,有以下几种父子组件生命周期的组合

在这里插入图片描述
(1)调用异步方法改变数据和视图都在是父组件和子组件的beforeMount里

beforeMount() {
console.log('父组件的beforeMount') this.loadCourses()},beforeMount() {
console.log('子组件的beforeMount') this.loadCourses()},

(2)调用异步方法改变数据和视图,父组件的在mounted 里调用,子组件的在beforeMount里调用

mounted () {
console.log('父组件的mounted') this.loadCourses()},beforeMount() {
console.log('子组件的beforeMount') this.loadCourses()},

(3)调用异步方法改变数据和视图,父组件的在beforeMount里调用,子组件的在mounted 里调用

beforeMount() {
console.log('父组件的beforeMount') this.loadCourses()},mounted () {
console.log('子组件的mounted ') this.loadCourses()},

转载地址:http://rtvrn.baihongyu.com/

你可能感兴趣的文章
腾讯公测云开发低码!实战评测
查看>>
.NET 5 开源工作流框架elsa技术研究
查看>>
C#-WinForm跨线程修改UI界面
查看>>
Amazing 2020
查看>>
代码改变世界,也改变了我
查看>>
【Git】Git-常用命令备忘录(一)
查看>>
2021,未来可期
查看>>
阿星Plus:基于abp vNext开源一个博客网站
查看>>
写给自己,2020的年终总结
查看>>
使用 ML.NET 识别乐高颜色块
查看>>
Flash 生命终止,HTML5能否完美替代?
查看>>
ML.NET生成器带来了许多错误修复和增强功能以及新功能
查看>>
微信适配国产操作系统:原生支持 Linux
查看>>
我的2020年终总结:新的角色,新的开始
查看>>
“开源、共享、创新” 2020 中国.NET开发者大会小结
查看>>
C# 9 新特性 —— 增强的模式匹配
查看>>
. NET5一出,. NET岗面试普遍喊难,真相是…
查看>>
强烈推荐:SiteServer CMS开源免费的企业级CMS系统!
查看>>
如何在 ASP.NET Core 中使用 NLog 的高级特性
查看>>
对CORS OPTIONS预检请求的一些思考
查看>>