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

日常练习另一部分

上次我的练习是使用vue3进行的前端训练,我上一个博客简单实现了使用路由的单页面跳转,他的好处的所有页面一起加载,并且只使用一个main和app.vue,我又在原有的基础上尝试了多页面跳转。
about.html

<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>关于我们 - Vue多页面应用</title><link rel="stylesheet" href="<%= BASE_URL %>css/common.css"></head><body><noscript><strong>请启用JavaScript以正常使用此应用</strong></noscript><div id="about-app"></div></body>
</html>

App.vue

<template><div class="container about-page"><div class="content"><h1>关于我们</h1><p>这是一个独立的关于页面,展示了多页面应用的能力。您可以通过下方按钮返回首页。</p><div class="button-container"><button class="btn"@click="goToHome">返回首页</button><button class="btn" @click="learnMore">了解更多</button></div></div></div>
</template><script>
export default {name: 'AboutPage',mounted() {this.animateContainer();},methods: {goToHome() {this.addLoadingToButton('.btn:first-child');setTimeout(() => {window.location.href = 'index.html#/';}, 500);},learnMore() {alert('这是关于页的一个功能按钮');},addLoadingToButton(selector) {const btn = document.querySelector(selector);if (btn) btn.classList.add('loading');},animateContainer() {const container = document.querySelector('.container');if (!container) return;container.style.opacity = '0';container.style.transform = 'translateY(20px)';setTimeout(() => {container.style.transition = 'opacity 0.5s, transform 0.5s';container.style.opacity = '1';container.style.transform = 'translateY(0)';}, 100);}}
}
</script>

main.js

import { createApp } from 'vue'
import App from './App.vue'createApp(App).mount('#about-app')

home.html

<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>首页 - Vue多页面应用</title><link rel="stylesheet" href="<%= BASE_URL %>css/common.css"></head><body><noscript><strong>请启用JavaScript以正常使用此应用</strong></noscript><div id="app"></div></body>
</html>

App.vue

<template><!-- 添加根容器确保正确挂载 --><div id="app"><div class="container"><div class="content"><!-- 添加错误边界处理 --><router-view v-slot="{ Component, route }"><transition name="fade" mode="out-in"><div v-if="route.matched.length"><component :is="Component" /></div><div v-else class="error-view"><h2>页面未找到</h2><p>请求的路径 "{{ route.path }}" 不存在</p><button @click="goHome">返回首页</button></div></transition></router-view></div></div></div>
</template><script>
export default {name: 'App',methods: {goHome() {// 确保使用正确的首页路径this.$router.push({ name: 'home' });}}
}
</script>

main.js

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'createApp(App).use(router).mount('#app')

css文件不赘述,效果如下:
image
点击返回首页就是我上个练习的界面,点击了解更多则是我的一个另小功能测试,也不用赘述。

http://www.gsyq.cn/news/9564.html

相关文章:

  • 每天一个安卓测试开发小知识之 (六)---常用的adb 命令第四期
  • 视频融合平台EasyCVR国标GB28181视频诊断功能详解与实践
  • MyEMS 进阶应用:从单厂能耗管理到集团跨区域能源数据协同分析
  • avalonia android TextBox多行模式下回车会关闭输入法问题
  • client-go限速之QPS、Burst 和 RateLimiter
  • python实现网站登录会话脚本 - wanghongwei
  • 基于java+springboot的社区居民诊疗健康管理系统(源代码+文档+讲解视频) - 指南
  • 时序数据库IoTDB的六大实用场景盘点 - 指南
  • K8S的CoreDns配置文件添加域名解析
  • nodify_介绍及安装
  • MQTT协议(消息队列遥测传输)
  • 【低代码平台之应用构建展示】数智化贸易订单管理平台
  • Threading 串行VS并发
  • parallel index
  • 微指令控制器基本原理
  • 一个拒绝过度设计的 .NET 快速开发框架:开箱即用,专注干活
  • React 学习笔记4 Diffing/脚手架 - 详解
  • VisualStudio-Python-工具指南-全-
  • 深入解析:Spring Boot注解
  • Gevent和Subprocess问题
  • WPF ListBox loaded 76.6M items with imagesource
  • 【数据结构】双向链表 - 指南
  • 告别“能源糊涂账”:MyEMS如何帮企业把能耗数据“算明白、用到位”
  • 完整教程:ElasticSearch倒排索引原理
  • 负载排查和分析三
  • 完整教程:线程、进程、协程
  • CF913G Power Substring
  • ES集群部署-EFK架构实战 - 实践
  • 《BOE解忧实验室》第四季圆满收官 以科技重塑文化生活新范式
  • 洛谷P2261 [CQOI2007] 余数求和