Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue3 loading

作者:烟寂断魂   发布日期:2025-10-27   浏览:57

// Vue 3 Loading 示例代码

<template>
  <div v-if="isLoading" class="loading">Loading...</div>
  <div v-else>
    <!-- 这里可以放置你想要显示的内容 -->
    Content Loaded!
  </div>
</template>

<script>
import { ref, onMounted } from 'vue';

export default {
  setup() {
    const isLoading = ref(true);

    // 模拟加载数据的过程
    onMounted(() => {
      setTimeout(() => {
        isLoading.value = false;
      }, 2000); // 2秒后停止加载
    });

    return {
      isLoading,
    };
  },
};
</script>

<style scoped>
.loading {
  font-size: 24px;
  color: #ccc;
}
</style>

解释说明:

  1. 模板部分 (<template>):

    • 使用 v-ifv-else 来控制显示加载状态或内容。
    • isLoadingtrue 时,显示 "Loading..." 的提示信息;否则显示实际内容。
  2. 脚本部分 (<script>):

    • 使用 ref 创建一个响应式的变量 isLoading,初始值为 true
    • 使用 onMounted 钩子函数模拟数据加载过程,2秒后将 isLoading 设置为 false,表示加载完成。
  3. 样式部分 (<style scoped>):

    • 简单设置了加载提示文字的样式,字体大小为 24px,颜色为灰色 (#ccc)。

上一篇:vue 垂直居中

下一篇:vue withdefaults

大家都在看

vue js for循环

vue.config.js 配置

vue.config.js configu

node.js vue

vue3组件传值的方式

vue3 子路由

vue3 router传参

vue 图表组件

vue3+vite+ts

vue3watch监听多个变量

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站