金坛市政建设有限公司网站,wordpress 撰写设置,网站建设阶段性工作重点,汽车销售网站模板 cms问题描述
uniapp常用的有#xff1a;页面和组件#xff0c;并且页面和组件各自有各自的生命周期函数#xff0c;那么在页面/组件请求数据时#xff0c;是用created呢#xff0c;还是用onLoad呢#xff1f; 先说结论:
组件使用组件的生命周期#xff0c;页面使用页面的…问题描述
uniapp常用的有页面和组件并且页面和组件各自有各自的生命周期函数那么在页面/组件请求数据时是用created呢还是用onLoad呢 先说结论:
组件使用组件的生命周期页面使用页面的生命周期。
例如组件使用created请求数据页面使用onLoad请求数据。 参考文章
uni-app子组件onLoad、onReady事件无效_uniapp 组件 onload-CSDN博客 可以看到Header组件并没有触发onLoad和onReady函数所以组件中不要使用页面的生命周期。
templateview classcontentHeader //view
/templatescriptimport Header from ../../components/Header/Header.vueexport default {components: {Header},data() {return {title: Hello}},mounted() {console.log(index mounted);},created() {console.log(index created);},onReady() {console.log(index onReady);},onInit() {console.log(index onInit);},onLoad() {console.log(index onLoad);},onShow() {console.log(index onShow);},methods: {}}
/scripttemplateviewthis is header/view
/templatescriptexport default {name:Header,data() {return {};},mounted() {console.log(header mounted);},created() {console.log(header created);},onReady() {console.log(header onReady);},onInit() {console.log(header init);},onLoad() {console.log(header load);},onShow() {console.log(header show);}}
/scriptstyle langscss/style