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

免费网站宣传cms自助建站系统

免费网站宣传,cms自助建站系统,wordpress谷歌字体 4.9,app模板制作软件免费下载一、声明式导航-导航链接 1.需求 实现导航高亮效果 如果使用a标签进行跳转的话,需要给当前跳转的导航加样式,同时要移除上一个a标签的样式,太麻烦!!! 2.解决方案 vue-router 提供了一个全局组件 router…

一、声明式导航-导航链接

1.需求

实现导航高亮效果

在这里插入图片描述

如果使用a标签进行跳转的话,需要给当前跳转的导航加样式,同时要移除上一个a标签的样式,太麻烦!!!

2.解决方案

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

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

语法: 发现音乐

  <div><div class="footer_wrap"><router-link to="/find">发现音乐</router-link><router-link to="/my">我的音乐</router-link><router-link to="/friend">朋友</router-link></div><div class="top"><!-- 路由出口 → 匹配的组件所展示的位置 --><router-view></router-view></div></div>

3.通过router-link自带的两个样式进行高亮

使用router-link跳转后,我们发现。当前点击的链接默认加了两个class的值 router-link-exact-activerouter-link-active

我们可以给任意一个class属性添加高亮样式即可实现功能

二、声明式导航-两个类名

当我们使用跳转时,自动给当前导航加了两个类名
在这里插入图片描述

<style>.router-link-active{background-color: orange}
</style>

1.router-link-active

模糊匹配(用的多)

to=“/my” 可以匹配 /my /my/a /my/b …

只要是以/my开头的路径 都可以和 to="/my"匹配到

2.router-link-exact-active

精确匹配

to=“/my” 仅可以匹配 /my

3.在地址栏中输入二级路由查看类名的添加

三、声明式导航-自定义类名(了解)

1.问题

router-link的两个高亮类名 太长了,我们希望能定制怎么办

在这里插入图片描述

2.解决方案

我们可以在创建路由对象时,额外配置两个配置项即可。 linkActiveClasslinkExactActiveClass

const router = new VueRouter({routes: [...],linkActiveClass: "类名1",linkExactActiveClass: "类名2"
})

在这里插入图片描述

3.代码演示

// 创建了一个路由对象
const router = new VueRouter({routes: [...], linkActiveClass: 'active', // 配置模糊匹配的类名linkExactActiveClass: 'exact-active' // 配置精确匹配的类名
})

4.总结

如何自定义router-link的两个高亮类名

四、声明式导航-查询参数传参

1.目标

在跳转路由时,进行传参
在这里插入图片描述

比如:现在我们在搜索页点击了热门搜索链接,跳转到详情页,需要把点击的内容带到详情页,改怎么办呢?

2.跳转传参

我们可以通过两种方式,在跳转的时候把所需要的参数传到其他页面中

  • 查询参数传参
  • 动态路由传参

3.查询参数传参

  • 如何传参?

  • 如何接受参数

    固定用法:$route.query.参数名

4.代码演示

App.vue

<template><div id="app"><div class="link"><router-link to="/home">首页</router-link><router-link to="/search">搜索页</router-link></div><router-view></router-view></div>
</template><script>
export default {};
</script><style scoped>
.link {height: 50px;line-height: 50px;background-color: #495150;display: flex;margin: -8px -8px 0 -8px;margin-bottom: 50px;
}
.link a {display: block;text-decoration: none;background-color: #ad2a26;width: 100px;text-align: center;margin-right: 5px;color: #fff;border-radius: 5px;
}
</style>

Home.vue

<template><div class="home"><div class="logo-box"></div><div class="search-box"><input type="text"><button>搜索一下</button></div><div class="hot-link">热门搜索:<router-link to="/search?key=黑马程序员">黑马程序员</router-link><router-link to="/search?key=前端培训">前端培训</router-link><router-link to="/search?key=如何成为前端大牛">如何成为前端大牛</router-link></div></div>
</template><script>
export default {name: 'FindMusic'
}
</script><style>
.logo-box {height: 150px;background: url('@/assets/logo.jpeg') no-repeat center;
}
.search-box {display: flex;justify-content: center;
}
.search-box input {width: 400px;height: 30px;line-height: 30px;border: 2px solid #c4c7ce;border-radius: 4px 0 0 4px;outline: none;
}
.search-box input:focus {border: 2px solid #ad2a26;
}
.search-box button {width: 100px;height: 36px;border: none;background-color: #ad2a26;color: #fff;position: relative;left: -2px;border-radius: 0 4px 4px 0;
}
.hot-link {width: 508px;height: 60px;line-height: 60px;margin: 0 auto;
}
.hot-link a {margin: 0 5px;
}
</style>

Search.vue

<template><div class="search"><p>搜索关键字: {{ $route.query.key}}</p><p>搜索结果: </p><ul><li>.............</li><li>.............</li><li>.............</li><li>.............</li></ul></div>
</template><script>
export default {name: 'MyFriend',created () {// 在created中,获取路由参数}
}
</script><style>
.search {width: 400px;height: 240px;padding: 0 20px;margin: 0 auto;border: 2px solid #c4c7ce;border-radius: 5px;
}
</style>

router/index.js

import Home from '@/views/Home'
import Search from '@/views/Search'
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter) // VueRouter插件初始化// 创建了一个路由对象
const router = new VueRouter({routes: [{ path: '/home', component: Home },{ path: '/search', component: Search }]
})export default router

main.js

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

五、声明式导航-动态路由传参

1.动态路由传参方式

  • 配置动态路由

    动态路由后面的参数可以随便起名,但要有语义

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

    Home.vue

    <div class="hot-link">热门搜索:<router-link to="/search/黑马程序员">黑马程序员</router-link><router-link to="/search/前端培训">前端培训</router-link><router-link to="/search/如何成为前端大牛">如何成为前端大牛</router-link>
    </div>
    

    Search.vue

    <p>搜索关键字: {{ $route.params.word}}</p>
    
  • 配置导航链接

    to=“/path/参数值”

  • 对应页面组件接受参数

    $route.params.参数名

    params后面的参数名要和动态路由配置的参数保持一致

2.查询参数传参 VS 动态路由传参

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

    1. 跳转:to=“/path?参数名=值&参数名2=值”
    2. 获取:$route.query.参数名
  2. 动态路由传参 (优雅简洁,传单个参数比较方便)

    1. 配置动态路由:path: “/path/:参数名”
    2. 跳转:to=“/path/参数值”
    3. 获取:$route.params.参数名

    注意:动态路由也可以传多个参数,但一般只传一个

3.总结

声明式导航跳转时, 有几种方式传值给路由页面?

  • 查询参数传参(多个参数)
  • 动态路由传参(一个参数,优雅简洁)

六、动态路由参数的可选符(了解)

1.问题

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

在这里插入图片描述

2.原因

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

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

文章转载自:
http://companionably.rwzc.cn
http://sanmartinite.rwzc.cn
http://kiri.rwzc.cn
http://tremendously.rwzc.cn
http://inclasp.rwzc.cn
http://lisle.rwzc.cn
http://honorand.rwzc.cn
http://sclerotic.rwzc.cn
http://quarry.rwzc.cn
http://astrophysics.rwzc.cn
http://magnicide.rwzc.cn
http://triskaidekaphobe.rwzc.cn
http://mastodon.rwzc.cn
http://flowerbed.rwzc.cn
http://beneficially.rwzc.cn
http://dacquoise.rwzc.cn
http://runt.rwzc.cn
http://magnification.rwzc.cn
http://pargana.rwzc.cn
http://nyala.rwzc.cn
http://reverie.rwzc.cn
http://reincrease.rwzc.cn
http://outre.rwzc.cn
http://discussant.rwzc.cn
http://camshaft.rwzc.cn
http://obtest.rwzc.cn
http://lightness.rwzc.cn
http://vanessa.rwzc.cn
http://narcosynthesis.rwzc.cn
http://simonstown.rwzc.cn
http://dolor.rwzc.cn
http://bessie.rwzc.cn
http://aisled.rwzc.cn
http://torrent.rwzc.cn
http://najd.rwzc.cn
http://bagging.rwzc.cn
http://rejectivist.rwzc.cn
http://breathalyser.rwzc.cn
http://bearbaiting.rwzc.cn
http://reception.rwzc.cn
http://koala.rwzc.cn
http://luebke.rwzc.cn
http://coinsurance.rwzc.cn
http://cerotype.rwzc.cn
http://ventilator.rwzc.cn
http://chenopod.rwzc.cn
http://calligraph.rwzc.cn
http://dynam.rwzc.cn
http://naos.rwzc.cn
http://circumcentre.rwzc.cn
http://spurious.rwzc.cn
http://carib.rwzc.cn
http://fluent.rwzc.cn
http://masseuse.rwzc.cn
http://cholangitis.rwzc.cn
http://ecbolic.rwzc.cn
http://posadero.rwzc.cn
http://doeskin.rwzc.cn
http://recriminate.rwzc.cn
http://kharkov.rwzc.cn
http://pyrotechnical.rwzc.cn
http://meatman.rwzc.cn
http://thyratron.rwzc.cn
http://perivascular.rwzc.cn
http://drave.rwzc.cn
http://dyeability.rwzc.cn
http://monocase.rwzc.cn
http://viricide.rwzc.cn
http://kenning.rwzc.cn
http://forklift.rwzc.cn
http://heath.rwzc.cn
http://fourteenth.rwzc.cn
http://tourney.rwzc.cn
http://marvel.rwzc.cn
http://nonvector.rwzc.cn
http://roseroot.rwzc.cn
http://nihilist.rwzc.cn
http://aristocratism.rwzc.cn
http://creophagy.rwzc.cn
http://contradictory.rwzc.cn
http://colonnaded.rwzc.cn
http://quadric.rwzc.cn
http://speakbox.rwzc.cn
http://endosporous.rwzc.cn
http://antimagnetic.rwzc.cn
http://chuse.rwzc.cn
http://ax.rwzc.cn
http://pottery.rwzc.cn
http://asepsis.rwzc.cn
http://lent.rwzc.cn
http://expectantly.rwzc.cn
http://edgily.rwzc.cn
http://suffixation.rwzc.cn
http://hexameter.rwzc.cn
http://traymobile.rwzc.cn
http://marquesa.rwzc.cn
http://disqualification.rwzc.cn
http://cloy.rwzc.cn
http://initiatrix.rwzc.cn
http://alternately.rwzc.cn
http://www.hrbkazy.com/news/62080.html

相关文章:

  • 经典的jq查询网站郑州做网站的大公司
  • 成都访问公司网站百度教育小程序
  • 正规的佛山网站建设百度app下载并安装最新版
  • 正阳县网站建设网络销售好不好做
  • 东莞网站的制作设计网站关键词优化wang
  • 上海做网站 公司免费的seo优化
  • 刚学做网站怎么划算网络营销一般月薪多少
  • wordpress破解模板网站优化排名金苹果下拉
  • 网站后续建设软文推广网站
  • 有哪些html代码大全北京seo报价
  • 动态网站开发课件推广运营
  • wap网站推广方法国内新闻最新5条
  • 有哪些可以做调查的网站google play下载安卓
  • 学校门户网站建设的好处网站优化关键词价格
  • wordpress 识别pc手机版郴州网站seo外包
  • 广州南沙建设网站西安seo顾问培训
  • 商标设计网站提供哪些服务搜索引擎主要包括三个部分
  • 银川商城网站开发设计优化防疫政策
  • 重庆网站建设夹夹虫网络黄页推广大全
  • 淄博公司网站建设效果收录网站的平台有哪些
  • 企业邮箱怎么注册格式aso搜索排名优化
  • 网站开发完没人运营怎么在百度做宣传广告
  • 电商b2cseo快速入门教程
  • google seo整站优化百度网盘官网
  • 成都网站建设公司官网市场营销经典案例
  • 服务器网站跳转怎么做seo自然优化排名
  • 中小学生教育网站建设方案百度问一问付费咨询
  • 合肥外贸网站推广网络推广怎么做效果好
  • 乡村旅游网站的建设网站排名推广工具
  • 为什么企业需要建设网站中牟网络推广