主页

uniapp的组件生命周期

勿宿迟迟霜   IP属地: 青海
0 点赞 0阅读 1264

以下是一个简单的uniapp组件的例子,展示了这些生命周期钩子的使用:

<template>
  <view>
    <text>{{ message }}</text>
  </view>
</template>
 
<script>
export default {
  data() {
    return {
      message: 'Hello World'
    }
  },
  beforeCreate() {
    console.log('组件实例创建之前');
  },
  created() {
    console.log('组件实例创建之后');
  },
  beforeMount() {
    console.log('组件模板加载之前');
  },
  mounted() {
    console.log('组件模板加载之后');
  },
  beforeUpdate() {
    console.log('组件数据更新之前');
  },
  updated() {
    console.log('组件数据更新之后');
  },
  beforeDestroy() {
    console.log('组件实例销毁之前');
  },
  destroyed() {
    console.log('组件实例销毁之后');
  }
}
</script>


© 著作权归作者所有,转载或内容合作请联系作者