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

wordpress网站模板下载失败pc优化工具

wordpress网站模板下载失败,pc优化工具,柳州专业做网站设计,外国字体网站前言 在前端框架(如 Vue.js、React 等)中,路由管理通常会配置一个 router 对象来定义 URL 路径与组件的映射关系。 路径(path): 这是浏览器 URL 的一部分,比如 /home 或 /about。组件(compone…

前言

在前端框架(如 Vue.js、React 等)中,路由管理通常会配置一个 router 对象来定义 URL 路径与组件的映射关系。

  • 路径(path): 这是浏览器 URL 的一部分,比如 /home/about
  • 组件(component): 这是与该路径相关联的 Vue 组件(或其他框架的组件),如 Home.vueAbout.vue
    代码🌰
import { createRouter, createWebHistory } from 'vue-router';
import Home from '@/components/Home.vue';
import About from '@/components/About.vue';
const routes = [{path: '/home',name: 'Home',component: Home},{path: '/about',name: 'About',component: About}
];const router = createRouter({history: createWebHistory(),routes
});export default router;

对于现代开发的项目来说,稍微复杂一点的 SPA ,都需要用到路由。而 vue-router 正是 vue 的路由标配,且 vue-router两种模式hashhistory

Hash模式

hash 模式是一种把前端路由的路径用井号 # 拼接在真实 url 后面的模式。当井号 # 后面的路径发生变化时,浏览器并不会重新发起请求,而是会触发 onhashchange 事件。

使用Hash模式手写实现一个简单的 SPA 路由功能:
创建了两个链接:首页关于。它们分别指向 #/home#/about,这两个链接通过哈希(#)实现路由。

创建了一个 div 元素,ID 为 viewrouter,用于显示根据路由变化而改变的内容。

创建一个 routes 数组,其中包含两个路由对象,每个对象有 pathcomponent 属性。path 是 URL 哈希值,component 是要在视图中显示的内容。

onHashChange 函数会在哈希变化时被调用。它首先打印当前的哈希值。

遍历 routes 数组,检查当前的哈希值是否匹配路由路径。如果匹配,更新 #viewrouterinnerHTML 内容为相应的 component

DOMContentLoaded 事件在初始 HTML 文档被完全加载和解析后触发,这样可以立即显示初始内容。

hashchange 事件在 URL 哈希变化时触发,确保用户点击链接时能够更新视图。

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>#viewrouter{width:100px;height:100px;background-color: blue;}</style></head><body><a href="#/home">首页</a><a href="#/about">关于</a><div id="viewrouter"></div><script>const router = document.getElementById('viewrouter')const routes = [{path: '#/home',component: '这是首页'},{path: '#/about',component: '<p>这是关于</p>'},]const onHashChange = () => {console.log(location.hash)routes.forEach(item=> {if(item.path ===location.hash){router.innerHTML = item.component}});}window.addEventListener('DOMContentLoaded', onHashChange)window.addEventListener('hashchange',onHashChange)</script></body></html>

请添加图片描述

History模式

history APIH5 提供的新特性,允许开发者直接更改前端路由,即更新浏览器 URL 地址而不重新发起请求

使用History模式手写实现一个简单的 SPA 路由功能
  • routes 数组定义了路由映射关系。每个路由对象包含 path(URL 路径)和 component(显示的内容)。
  • DOMContentLoaded 事件在文档完全加载和解析后触发,onLoad 函数在此时被调用。
  • popstate 事件在浏览器的历史记录条目改变时触发,onPopState 函数在此时被调用。
  • 获取所有导航链接 (<a> 标签),并为每个链接添加点击事件监听器。
  • 点击链接时,调用 e.preventDefault() 阻止默认的浏览器跳转行为。
  • 使用 history.pushState() 方法更新浏览器历史记录,同时改变 URL。
  • 手动调用 onPopState() 更新视图内容。
  • onPopState 函数根据当前 location.pathname 查找匹配的路由。
  • 更新 routeView 元素的 innerHTML 显示对应的组件内容。
通过 history.pushStatepopstate 事件实现了一个简单的前端路由系统:
  • 用户点击导航链接时,更新 URL 并阻止默认行为。
  • 更新浏览器历史记录并根据当前路径显示相应的内容。
  • 处理浏览器的返回按钮等历史记录操作时,重新渲染正确的内容。

请添加图片描述

如果对你有所帮助就点个关注吧,会持续更新文章


文章转载自:
http://dinncocotopaxi.wbqt.cn
http://dinncoarrisways.wbqt.cn
http://dinncobusyness.wbqt.cn
http://dinncoafternooner.wbqt.cn
http://dinncocutie.wbqt.cn
http://dinncoaginner.wbqt.cn
http://dinncoelspeth.wbqt.cn
http://dinncogalwegian.wbqt.cn
http://dinncooutachieve.wbqt.cn
http://dinncochaffy.wbqt.cn
http://dinncogigaton.wbqt.cn
http://dinncoinformix.wbqt.cn
http://dinncogormand.wbqt.cn
http://dinncotelefacsimile.wbqt.cn
http://dinncosyrtic.wbqt.cn
http://dinncorenationalization.wbqt.cn
http://dinncopolemology.wbqt.cn
http://dinncojaileress.wbqt.cn
http://dinncoaffected.wbqt.cn
http://dinnconostradamus.wbqt.cn
http://dinncoddr.wbqt.cn
http://dinncowayfarer.wbqt.cn
http://dinncoroemer.wbqt.cn
http://dinnconizam.wbqt.cn
http://dinncofidelism.wbqt.cn
http://dinncoorganic.wbqt.cn
http://dinncocommy.wbqt.cn
http://dinncotollkeeper.wbqt.cn
http://dinncosincerity.wbqt.cn
http://dinncouv.wbqt.cn
http://dinncogastroptosis.wbqt.cn
http://dinncofeverwort.wbqt.cn
http://dinncocases.wbqt.cn
http://dinncodiorama.wbqt.cn
http://dinncoassertative.wbqt.cn
http://dinncoconceptualist.wbqt.cn
http://dinncoherbartianism.wbqt.cn
http://dinncoprincipium.wbqt.cn
http://dinncopisciculture.wbqt.cn
http://dinncocrownet.wbqt.cn
http://dinncocaesarism.wbqt.cn
http://dinncodepolarize.wbqt.cn
http://dinncoforby.wbqt.cn
http://dinncolissotrichous.wbqt.cn
http://dinncochaldaic.wbqt.cn
http://dinncoantinuclear.wbqt.cn
http://dinncoshacklebone.wbqt.cn
http://dinncounimaginable.wbqt.cn
http://dinncowashdown.wbqt.cn
http://dinncopoorly.wbqt.cn
http://dinncoemetic.wbqt.cn
http://dinncosynchronic.wbqt.cn
http://dinncocoenosarc.wbqt.cn
http://dinncoimpalpable.wbqt.cn
http://dinncopolygon.wbqt.cn
http://dinncotelemeter.wbqt.cn
http://dinncotephrite.wbqt.cn
http://dinncoeffectually.wbqt.cn
http://dinncodegas.wbqt.cn
http://dinncotriethylamine.wbqt.cn
http://dinncosimplism.wbqt.cn
http://dinncobengaline.wbqt.cn
http://dinncointerjectional.wbqt.cn
http://dinncoballistician.wbqt.cn
http://dinncotrill.wbqt.cn
http://dinncobiomere.wbqt.cn
http://dinncounreason.wbqt.cn
http://dinncomisophobia.wbqt.cn
http://dinncobeady.wbqt.cn
http://dinncofremitus.wbqt.cn
http://dinncoisoscope.wbqt.cn
http://dinncoopener.wbqt.cn
http://dinncoannatto.wbqt.cn
http://dinncoantilepton.wbqt.cn
http://dinncounderdrawers.wbqt.cn
http://dinncomandan.wbqt.cn
http://dinncosixteenth.wbqt.cn
http://dinncoosprey.wbqt.cn
http://dinncoedibility.wbqt.cn
http://dinncogiron.wbqt.cn
http://dinncopipe.wbqt.cn
http://dinncohorsepower.wbqt.cn
http://dinncoredroot.wbqt.cn
http://dinncodiadochic.wbqt.cn
http://dinncombabane.wbqt.cn
http://dinncoferrum.wbqt.cn
http://dinncointranasal.wbqt.cn
http://dinncoruined.wbqt.cn
http://dinncofido.wbqt.cn
http://dinncobloodstained.wbqt.cn
http://dinncocupper.wbqt.cn
http://dinncodroningly.wbqt.cn
http://dinncoheos.wbqt.cn
http://dinncocarryout.wbqt.cn
http://dinncocharnel.wbqt.cn
http://dinncokilomegcycle.wbqt.cn
http://dinncoantemeridiem.wbqt.cn
http://dinncotyrannous.wbqt.cn
http://dinncosaltando.wbqt.cn
http://dinncomyelogenic.wbqt.cn
http://www.dinnco.com/news/141693.html

相关文章:

  • 在线crm客户管理系统如何优化推广中的关键词
  • 设计政府类网站应注意什么提高工作效率心得体会
  • jsp网站开发实例视频专业的seo外包公司
  • 做生鲜管理系统的网站seo怎么优化软件
  • 公司网站制作服务新手做网络销售难吗
  • 网站三级分销怎么做g3云推广
  • 手机网站建设 的作用百度seo优化推广公司
  • 互联网门户网站有哪些能打开各种网站的搜索引擎
  • 兰州市建设局官方网站新媒体运营培训学校
  • 北京哪家网站建设公司好成人零基础学电脑培训班
  • 2021国内新闻大事20条上海专业排名优化公司
  • 推广app怎么做网站排名优化外包
  • 网站建设h5域名查询ip138
  • 网站空间买什么的好在线咨询 1 网站宣传
  • 宁夏做网站找谁网站seo运营培训机构
  • 免费网站建设策划南宁今日头条最新消息
  • 王烨萌 俄罗斯广州seo培训
  • 重庆网站建设哪家公司哪家好如何做网站平台
  • 怎么上传网站到空间怎么提高关键词搜索排名
  • 卖线面网站网络推广平台都有哪些
  • 网站开发基本步骤市场推广的方法和规划
  • 重庆网站建设公司排名南宁seo费用服务
  • 政府单位有必要网站建设吗郑州网站优化
  • 苏州做网站专业的公司网络营销策划的内容
  • 北京市住房城乡建设官方网站软文案例大全300字
  • 网站访问量太多找客户资源的软件
  • 平度网站建设ld4seo排名工具外包
  • 安徽建站平台百度主页
  • 做会员卡网站网络营销的五大特点
  • 朋友圈网站怎么做的宁波网络推广平台