首页 > TAG信息列表 > onBeforeMount

vue3在setup中获取异步数据并暴露出去

使用生命周期钩子onBeforeMount setup(){ const postData = ref([]) onBeforeMount(async () => { const res = await axios.get('http://localhost:3002/postdata') postData.value = res.data }) return { ... postData }

vue3生命周期

// vue2.xexport default { data () { return {} }, methods: { ... }, beforeCreate() {}, created() {}, beforeMount() {}, mounted() {}, beforeUpdate() {}, updated() {}, beforeDestroy() {}, destroyed() {} }   // vue3.x import

vue3-生命周期

  链接:http://ggz.longpanda.top/article_detail?id=26   import { onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted, onActivated, onDeactivated, onErrorCaptured } from 'vue' export default { setup() {

vue3 组合api的简单使用

  //compostion api (组合api) import { ref, reactive,onBeforeMount, onMounted,onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted,computed } from 'vue' export default{ setup(){ // 非响应式变量 let msg = "hello wrold";