当前位置: 首页 > news >正文

日常练习一部分

这一次练习不使用后端,只进行对使用vue3的前端练习,包括两种不同的跳转方式:
我的部分代码大致如下:
DashboardView.vue:

<template><div><h1>仪表盘视图</h1><p>这是您的个人仪表盘,显示各种统计信息。</p><div class="stats-container"><div class="stat-card"><h3>访问量</h3><p class="stat-value">1,254</p></div><div class="stat-card"><h3>用户数</h3><p class="stat-value">548</p></div><div class="stat-card"><h3>完成率</h3><p class="stat-value">89%</p></div></div><button class="btn back-btn" @click="goHome">返回首页</button></div>
</template><script>
export default {methods: {goHome() {this.$router.push({ name: 'home' });}}
}
</script><style scoped>
.stats-container {display: flex;justify-content: center;gap: 20px;margin: 40px 0;
}.stat-card {background: linear-gradient(135deg, #f0f7ff, #e6f2ff);border-radius: 12px;padding: 20px;text-align: center;min-width: 150px;box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}.stat-value {font-size: 2.2rem;font-weight: 700;color: #2c3e50;margin: 10px 0;
}.back-btn {margin-top: 30px;
}
</style>

HomeView.vue``

<template><div><div class="nav-container"><router-link :to="{ name: 'home' }" class="nav-link" active-class="active">首页</router-link><router-link to="/dashboard" class="nav-link" active-class="active">仪表盘</router-link><router-link to="/profile" class="nav-link" active-class="active">个人中心</router-link></div><h1>欢迎来到首页</h1><p>这是一个使用Vue构建的多页面应用示例。点击下方按钮切换到不同视图。</p><div class="button-container"><button class="btn" @click="switchView('dashboard')">查看仪表盘</button><button class="btn" @click="switchView('profile')">查看个人中心</button><button class="btn about-btn" @click="goToAbout">前往关于页</button></div></div>
</template><script>
export default {name: 'HomeView',methods: {switchView(viewName) {this.$router.push({ name: viewName })},goToAbout() {this.addLoadingToButton('.about-btn');setTimeout(() => {window.location.href = 'about.html';}, 500);},addLoadingToButton(selector) {const btn = document.querySelector(selector);if (btn) btn.classList.add('loading');}}
}
</script>

ProfileView.vue

<template><div><h1>个人中心</h1><p>这是您的个人信息页面。</p><div class="profile-card"><div class="avatar"><div class="avatar-initial">U</div></div><div class="profile-info"><h3>用户名</h3><p>user@example.com</p><p>会员状态: <span class="premium">高级会员</span></p></div></div><button class="btn back-btn" @click="goHome">返回首页</button></div>
</template><script>
export default {methods: {goHome() {this.$router.push({ name: 'home' });}}
}
</script><style scoped>
.profile-card {display: flex;align-items: center;gap: 25px;background: white;border-radius: 15px;padding: 25px;margin: 30px auto;max-width: 500px;box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
}.avatar {width: 80px;height: 80px;border-radius: 50%;background: linear-gradient(135deg, #6a11cb, #2575fc);display: flex;align-items: center;justify-content: center;
}.avatar-initial {font-size: 2.5rem;font-weight: bold;color: white;
}.profile-info h3 {font-size: 1.8rem;margin-bottom: 10px;
}.premium {color: #ff7e5f;font-weight: 700;
}.back-btn {margin-top: 30px;
}
</style>

router.js:

import { createRouter, createWebHashHistory } from 'vue-router'
// 导入视图组件
const HomeView = () => import('./views/HomeView.vue')
const DashboardView = () => import('./views/DashboardView.vue')
const ProfileView = () => import('./views/ProfileView.vue')const routes = [{path: '/',name: 'home',component: HomeView,meta: { title: '首页' }},{path: '/dashboard',name: 'dashboard',component: DashboardView,meta: { title: '仪表盘' }},{path: '/profile',name: 'profile',component: ProfileView,meta: { title: '个人中心' }}
]const router = createRouter({history: createWebHashHistory(),routes
})router.beforeEach((to) => {document.title = to.meta.title || '默认标题';
});export default router

这一个部分就能实现单页面跳转,如下图:
image

http://www.wxhsa.cn/company.asp?id=3944

相关文章:

  • 世界史
  • 罗技M275鼠标滚轮断轴维修:建模+3D打印修复全过程
  • Unity:网络编程
  • 【比赛记录】2025CSP-S模拟赛45
  • PWN手的成长之路-01
  • SpringCloud全解:核心组件与实战案例 - 教程
  • 学起plus刷课
  • Windows 安装人大金仓数据库 KingbaseES_V008R006
  • Hadoop(十) - 教程
  • 如何注入像 MyBatis 一样注入接口
  • 深入解析:环境搭建与你的第一个 Next.js 应用
  • 在 Ubuntu 中处理中文路径
  • 10 个优质周公解梦网站推荐及解析参考
  • 202212_风二西_冰蝎流量分析
  • 记账:出入报表
  • [AGC028D] Chords 题解
  • 记账:报表
  • 记账:灵活转账
  • 记账:批量更新
  • 记账:水电气话费
  • 《原子习惯》-读书笔记1
  • 记账:记一笔
  • 记账:快速上手
  • 高二闲话 #1
  • dijkstra 学习笔记。
  • linux指令
  • char与varchar类型
  • 详细介绍:【MySQL】基本查询
  • 202109_鹤城杯_SQL注入
  • Madness - TryHackMe