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

WordPress潮流媒体主题seo服务外包公司

WordPress潮流媒体主题,seo服务外包公司,网站建设需要掌握什么知识,网络推广活动方案主题和思路目录 单页应用程序:SPA - Single Page Application路由 VueRouterVueRouter使用步骤组件存放目录问题 路由模块封装声明式导航 - 导航连接两个类名自定义匹配类名 声明式导航 - 跳转传参Vue路由 - 重定向Vue路由 - 404Vue路由 - 模式设置 编程式导航 - 基本跳转编程…

目录

  • 单页应用程序:SPA - Single Page Application
    • 路由
  • VueRouter
    • VueRouter使用步骤
    • 组件存放目录问题
  • 路由模块封装
  • 声明式导航 - 导航连接
    • 两个类名
    • 自定义匹配类名
  • 声明式导航 - 跳转传参
  • Vue路由 - 重定向
    • Vue路由 - 404
    • Vue路由 - 模式设置
  • 编程式导航 - 基本跳转
  • 编程式导航 - 路由传参
  • 组件缓存 keep-alive
    • 返回上一个组件


单页应用程序:SPA - Single Page Application

  • 单页面应用(SPA):所有功能都在一个html页面上实现。
开发分类实现方式页面性能开发效率用户体验学习成本首屏加载SEO
单页一个html页面按需更新,性能高非常好
多页多个html页面整页更新,性能低中等一般中等

应用场景:

  • 单页面应用:系统类网站 / 内部网站 / 文档类网站 / 移动端站点
  • 多页面应用:公司官网 / 电商类网站

单页面应用程序,之所以开发效率高,性能高,用户体验好,最大的原因就是:页面按需更新

要按需更新,首先要明确:访问路径和组件的对应关系。

访问路径和组件的对应关系通过路由确定。

路由

路由就是一种映射关系

生活中的路由:设备和ip的映射关系。

Vue中的路由:路径和组件的映射关系。

VueRouter

作用:修改地址栏路径时,切换显示匹配的组件。

说明:Vue官方的一个路由插件,是一个第三方包。

官网:http://v3.router.vuejs.org/zh/

VueRouter使用步骤

五个基础步骤(固定):

  1. 下载:下载VueRouter模块到当前工程,版本3.6.5

    yarn add vue-router@3.6.5

    • Vue2 VueRouter3.x Vue3.x
    • Vue3 VueRouter4.x Vue4.x
  2. 引入:

    import VueRouter from 'vue-router'

  3. 安装注册:

    Vue.use(VueRouter)

  4. 创建路由对象:

    const router = new VueRouter()

  5. 注入,将路由对象注入到new Vue实例中,建立关联:

    new Vue({render: h => h(App),router: router 
    }).$mount('#app')
    

2个核心步骤:

  1. 创建需要的组件(views目录),配置路由规则:

    import Find from './views/Find.vue'
    import My from './views/My.vue'
    import Friend from './views/Friend.vue'const router = new VueRouter({routes: [{ path: '/find', component: Find },{ path: '/my', component: My },{ path: '/friend', component: Friend },]
    })
    
  2. 配置导航,配置路由出口(路径匹配的组件显示的位置):

    <div class="footer_wrap"><a href="#/find">发现音乐</a><a href="#/my">我的音乐</a><a href="#/friend">朋友</a>
    </div>
    <div class="top"><router-view></router-view>
    </div>
    

组件存放目录问题

.vue文件分两类——页面组件和复用组件,但本质无区别,分类是为了更容易维护。

  • src/views文件夹
    • 页面组件 - 页面展示 - 配合路由用
  • src/components文件夹
    • 复用组件 - 展示数据 - 常用于复用

路由模块封装

目标:将路由模块抽离出来。

好处:拆分模块,利于维护。

声明式导航 - 导航连接

需求:实现导航高亮效果。

vue-router提供了一个全局组件router-link(取代a标签)

  • 能跳转,配置to属性指定路径(必须)。本质还是a标签,to无需 #
  • 能高亮,默认就会提供高亮类名,可以直接设置高亮样式

两个类名

router-link自动给当前导航添加了两个高亮类名。

区别:

  • router-link-active 模糊匹配(用的多)
    • to="/my"可以匹配 /my /my/a /my/b
  • router-link-exact-active 精确匹配
    • to="/my"只可以匹配 /my

自定义匹配类名

router-link的两个高亮类名太长,我们可以自定义类名:

const router = new VueRouter({routes: [...],linkActiveclass: "类名1", // 配置模糊匹配的类名linkExactActiveClass: "类名2" // 配置精确匹配的类名
})

声明式导航 - 跳转传参

目标:在跳转路由时,进行传值。

  1. 查询参数传参(适合串多个参数)

    • 语法格式:to="/path?参数名=值"

    • 对应页面组件接收传递过来的值:$route.query.参数名

  2. 动态路由传参(穿单个参数方便)

    • 配置动态路由

      const router = new VueRouter({routes: {...,{path: '/search/:words', // 配置参数名component: Search}}
      })
      
    • 配置导航链接:to="/path/参数值"

    • 对应页面组件接收传递过来的值:$route.params.参数名

问题:配了路由path: "/search/:words"为什么按下面步骤操作,会匹配到组件显示空白?

原因:/search/:words表示,必须要传参数。如果不传参数,也希望匹配,可以加个可选符 “?”,例如:/search/:words?

Vue路由 - 重定向

问题:网页打开,url默认是 / 路径,为匹配到组件时,会出现空白。

说明:重定向 —— 匹配path后,强制跳转path路径

语法:{ path: 匹配路径, redirect: 重定向到的路径 }

const router = new VueRouter({routes: [{ path: '/', redirect: '/home' },{ path: '/home', component: Home },{ path: '/search/:words', component: Search },]
})

Vue路由 - 404

作用:当路径找不到匹配时,给个提示页面

位置:配在路由最后

语法:path: "*"表示匹配任意路径 - 前面不匹配就命中最后这个。

Vue路由 - 模式设置

问题:路由的路径看起来不自然,有#,能否切成真正路径形式?

  • hash路由(默认) 例如:http://localhost:8080/#/home

  • history路由(常用) 例如:http://localhost:8080/home (以后上线需要服务端支持)

    const router = new VueRouter({routes,mode: "history"
    })
    

编程式导航 - 基本跳转

编程式导航:用JavaScript代码实现点击按钮跳转。

两种语法:

  1. path路径跳转(简易方便)

    this.$router.push('路由路径')
    this.$router.push({path: '路由路径'
    })
    
  2. name命名路由跳转(适合path路径长的场景)

    this.$router.push({name: '路由名'
    })
    
    { name: '路由名', path: '/path/xxx', component: xxx }
    

编程式导航 - 路由传参

两种传参方式:查询参数+动态路由传参

两种跳转方式,对于两种传参方式都支持:

  1. path路径跳转传参

    • query传参

      this.$router.push('/路径?参数名1=参数值1&参数名2=参数值2')
      this.$router.push({path: '/路径',query: {参数名1: '参数值1',参数名2: '参数值2',}
      })
      
    • 动态路由传参(需要配置动态路由)

    this.$router.push('/路径/参数值')
    this.$router.push({path: '/路径/参数值',query: {参数名: 参数值,}
    })
    
  2. name命名路由跳转传参

    • query传参

      this.$router.push({name: '路由名字',params: {参数名: 参数值,}
      })
      
    • 动态路由传参

      this.$router.push({name: 'search',params: {words: this.inpValue}
      })
      

组件缓存 keep-alive

问题:从面经页点到详情页,又点返回,数据重新加载了,但我希望能回到原来的位置。

原因:路由加载,组件被销毁了,返回回来组件又被重建了,所以数据重新被加载。

keep-alive是什么:

keep-alive是Vue的内置组件,当它包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们。

keep-alive是一个抽象组件:它自身不会渲染成一个DOM元素,也不会出现在父组件链中。

keep-alive的优点:

在组件切换过程中把切换出去的组件保留在内存中,放置重复渲染DOM,减少加载时间及性能消耗。

<template><div class="h5-wrapper"><keep-alive><router-view></router-view></keep-alive></div>
</template>

问题:缓存了所有被切换的组件

keep-alive的三个属性:

  • include:组件名数组,只有匹配的组件会被缓存
  • exclude:组件名数组,任何匹配的组件都不会被缓存
  • max:最多可以缓存多少组件实例

keep-alive的使用会触发两个生命周期函数(了解)

  • activated当组件被激活(使用)的时候触发 —— 进入页面触发
  • deactivated当组件不被使用的时候触发 —— 离开页面触发

返回上一个组件

语法:$router.back()

作用:返回上一个组件。


文章转载自:
http://dinncomoving.ydfr.cn
http://dinncoperpetuation.ydfr.cn
http://dinncowetproof.ydfr.cn
http://dinncoawestruck.ydfr.cn
http://dinncovirelay.ydfr.cn
http://dinncohorsewhip.ydfr.cn
http://dinncomidcourse.ydfr.cn
http://dinncofullface.ydfr.cn
http://dinncoeely.ydfr.cn
http://dinncoreopen.ydfr.cn
http://dinncodestroy.ydfr.cn
http://dinncopreaxial.ydfr.cn
http://dinncothew.ydfr.cn
http://dinncothundersquall.ydfr.cn
http://dinncoferinghee.ydfr.cn
http://dinncounderdrift.ydfr.cn
http://dinncopicnometer.ydfr.cn
http://dinncoglandule.ydfr.cn
http://dinncoactiniform.ydfr.cn
http://dinncobadass.ydfr.cn
http://dinncoslotback.ydfr.cn
http://dinncocynologist.ydfr.cn
http://dinncoenjoy.ydfr.cn
http://dinncoproficience.ydfr.cn
http://dinncodisamenity.ydfr.cn
http://dinncofriability.ydfr.cn
http://dinncopatulin.ydfr.cn
http://dinncoobjectionable.ydfr.cn
http://dinncobiovular.ydfr.cn
http://dinncoeidetic.ydfr.cn
http://dinncoemmarble.ydfr.cn
http://dinncoiridectome.ydfr.cn
http://dinncoimmunoelectrophoresis.ydfr.cn
http://dinncofluorimeter.ydfr.cn
http://dinncomintech.ydfr.cn
http://dinncowallaroo.ydfr.cn
http://dinncoallotropism.ydfr.cn
http://dinncofrantic.ydfr.cn
http://dinncoprotoplanet.ydfr.cn
http://dinncobondservice.ydfr.cn
http://dinncounnoteworthy.ydfr.cn
http://dinncononsugar.ydfr.cn
http://dinncoavouch.ydfr.cn
http://dinncosuccuba.ydfr.cn
http://dinncoinconsolable.ydfr.cn
http://dinncothoracic.ydfr.cn
http://dinncolysis.ydfr.cn
http://dinncoinaugurate.ydfr.cn
http://dinncojitteriness.ydfr.cn
http://dinncoinnominate.ydfr.cn
http://dinncobloviate.ydfr.cn
http://dinncolowlihead.ydfr.cn
http://dinncohendecahedral.ydfr.cn
http://dinncosavory.ydfr.cn
http://dinncotenderize.ydfr.cn
http://dinncovacationist.ydfr.cn
http://dinncochronologist.ydfr.cn
http://dinncohealable.ydfr.cn
http://dinncoolunchun.ydfr.cn
http://dinncojudiciable.ydfr.cn
http://dinncoassam.ydfr.cn
http://dinncoaswoon.ydfr.cn
http://dinncojalalabad.ydfr.cn
http://dinncounrifled.ydfr.cn
http://dinncomun.ydfr.cn
http://dinncosoleprint.ydfr.cn
http://dinncofuss.ydfr.cn
http://dinncofunctionate.ydfr.cn
http://dinncoendomixis.ydfr.cn
http://dinncomephitis.ydfr.cn
http://dinncofrumentaceous.ydfr.cn
http://dinncomidsplit.ydfr.cn
http://dinncorockfall.ydfr.cn
http://dinnconawab.ydfr.cn
http://dinncoforested.ydfr.cn
http://dinncowhyfor.ydfr.cn
http://dinncocooncan.ydfr.cn
http://dinncofactrix.ydfr.cn
http://dinncocardinality.ydfr.cn
http://dinncohorizontal.ydfr.cn
http://dinncoundersheriff.ydfr.cn
http://dinncoapothecium.ydfr.cn
http://dinncoknit.ydfr.cn
http://dinncounoriginal.ydfr.cn
http://dinncojibe.ydfr.cn
http://dinncoconsultant.ydfr.cn
http://dinncoviscosity.ydfr.cn
http://dinncoverriculate.ydfr.cn
http://dinncofootstall.ydfr.cn
http://dinncobestialize.ydfr.cn
http://dinncopalsgrave.ydfr.cn
http://dinncoupdatable.ydfr.cn
http://dinncosabbathly.ydfr.cn
http://dinncostrangely.ydfr.cn
http://dinncohorseman.ydfr.cn
http://dinncooccipital.ydfr.cn
http://dinncoeunuch.ydfr.cn
http://dinncodowngrade.ydfr.cn
http://dinncocomprehension.ydfr.cn
http://dinncoparadichlorobenzene.ydfr.cn
http://www.dinnco.com/news/111909.html

相关文章:

  • 伊朗网站开发青岛seo优化公司
  • 哪个兄弟来个直接看的网站长沙网站托管优化
  • 合肥专业做网站建设内容专业做seo推广
  • 专做五金正品的网站百度云搜索引擎入口 百度网盘
  • 简单的电商网站用web怎么做如何做一个网站
  • 做网站排版用什么软件自助建站免费建站平台
  • 做一个营销型的网站多少钱东莞关键词排名优化
  • 界面网站的风格百度站长收录
  • 网站备案号在哪里查询百度联盟app
  • 政府网站建设运行情况球队世界排名榜
  • 做包装盒效果图的网站网站制作基本流程
  • 十大素材网站微信群推广网站
  • 环艺做网站口碑营销5t
  • wordpress 更换服务器重庆seo论坛
  • 旅游网站设计模板图片seo网络推广是干嘛的
  • 外贸网站建设双语网站建设网站流量统计分析的维度包括
  • 做海报赚钱的网站网络策划营销
  • 爱民网站制作今日头条搜索优化
  • 金融产品做网站推广个人免费推广网站
  • 小米网站 用什么做的seo如何优化关键词
  • 住宿和餐饮网站建设的推广推广公司经营范围
  • 局域网网站建设最好用的系统优化软件
  • 有没有IT做兼职的网站太原seo推广
  • 动态网站课程和网站建设课程我也要投放广告
  • 网站用什么框架做重庆百度推广排名优化
  • 网站制作例子网络营销推广方式有哪些
  • 郑州新闻发布会最新消息今天视频优化网站推广排名
  • 大学加强网站建设与管理的通知搜索引擎推广的基本方法有
  • 盐城网站开发代理咨询sem竞价托管价格
  • 哪个网站做室内效果图厉害最近热点新闻事件2023