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

网站建设优化论坛ei网站怎么兼做

网站建设优化论坛,ei网站怎么兼做,崇信县门户网站领导动态,做装饰材料的网站文章目录 1.路由的封装抽离2.声明式导航 - 导航链接3.声明式导航-两个类名自定义匹配的类名 4.声明式导航 - 跳转传参查询参数传参动态路传参两种传参方式的区别动态路由参数可选符 5.Vue路由 - 重定向6.Vue路由 - 4047.Vue路由 - 模式设置8.编程式导航 - 两种路由跳转9.编程式… 文章目录 1.路由的封装抽离2.声明式导航 - 导航链接3.声明式导航-两个类名自定义匹配的类名 4.声明式导航 - 跳转传参查询参数传参动态路传参两种传参方式的区别动态路由参数可选符 5.Vue路由 - 重定向6.Vue路由 - 4047.Vue路由 - 模式设置8.编程式导航 - 两种路由跳转9.编程式导航 - 路由传参 1.路由的封装抽离 问题所有的路由配置都堆在main.js中合适吗 目标将路由模块抽离出来。好处拆分模块利于维护 之前所添加的路由配置都是写在main.js中的 方法src下面新建一个文件router里面建一个index.js在里面导入router index.js //一直换路径很麻烦可以用/view.Find(就是src就直接从src下面找是绝对路径) import Find from ../views/Find import My from ../views/My import Friend from ../views/Friendimport Vue from vue import VueRouter from vue-router Vue.use(VueRouter) //VueRouter插件初始化//创建了一个路由对象 const router new VueRouter({//routes 路由规则们routes:[{path:/find,component:Find},{path:/my,component:My},{path:/friend,component:Friend}]})export default routermain.js import Vue from vue import App from ./App.vue import router from ./router/index Vue.config.productionTip falsenew Vue({render: h h(App),router:router }).$mount(#app) 2.声明式导航 - 导航链接 需求实现导航高亮效果 vue-router 提供了一个全局组件router-link取代a标签 功能 ①能跳转配置to属性指定路径必须。标签还是a标签to无需# ②能高亮默认就会提供高亮类名可以直接设置高亮样式就是在控制台中直接找到对应的类名两个类名选一个就可以了 App.vue templatedivdiv classfooter_wraprouter-link to/find发现音乐/router-linkrouter-link to/my我的音乐/router-linkrouter-link to/friend朋友/router-link/divdiv classtop!-- 路由出口 → 匹配的组件所展示的位置 --router-view/router-view/div/div /templatescript export default {}; /scriptstyle.footer_wrap a.router-link-active{background-color: pink; }/style3.声明式导航-两个类名 说明router-link自动给当前导航添加了两个高亮类名 ①router-linkactive 模糊匹配用的多 to/my 可以匹配 /my /my/a /my/b ②router-link-exact-active 精确匹配 to/my 仅可以匹配 /my 自定义匹配的类名 Qrouter-link的两个高亮类名太长了希望能定制怎么办 只需要在router配置项中配两个配置项就可以了 4.声明式导航 - 跳转传参 目标在跳转路由时进行传值 查询参数传参动态路由传参 查询参数传参 ①语法格式如下 to /path?参数名 值 ②对应页面组件接收传递过来的值 $route.query.参数名 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 routerSearch.vue templatediv classsearch!-- 从地址栏导入关键字 --p搜索关键字: {{ $route.query.key }} /pp搜索结果: /pulli............./lili............./lili............./lili............./li/ul/div /templatescript export default {name: MyFriend,created () {// 在created中获取路由参数// this.$route.query.参数名 获取console.log(this.$route.query.key);} } /scriptHome.vue templatediv classhomediv classlogo-box/divdiv classsearch-boxinput typetextbutton搜索一下/button/divdiv classhot-link热门搜索router-link to/search?key黑马程序员黑马程序员/router-linkrouter-link to/search?key前端培训前端培训/router-linkrouter-link to/search?key如何成为前端大牛如何成为前端大牛/router-link/div/div /templatescript export default {name: FindMusic } /scriptApp.vue templatediv idappdiv classlinkrouter-link to/home首页/router-linkrouter-link to/search搜索页/router-link/divrouter-view/router-view/div /templatescript export default {}; /script动态路传参 ①配置动态路由 ②配置导航链接 to /path/参数值 ③对应页面组件接收传递过来的值 $route.params.参数名 index.js const router new VueRouter({routes: [{ path: /home, component: Home },//路由规则{ path: /search/:words, component: Search }// /~/:参数名参数名可以随便取] })Home.vuediv classhot-link热门搜索!-- 比查询参数传参的方法简洁 --router-link to/search/黑马程序员黑马程序员/router-linkrouter-link to/search/前端培训前端培训/router-linkrouter-link to/search/如何成为前端大牛如何成为前端大牛/router-link/div\Search.vue templatediv classsearchp搜索关键字: {{ $route.params.words }} /pp搜索结果: /pulli............./lili............./lili............./lili............./li/ul/div /templatescript export default {name: MyFriend,created () {// 在created中获取路由参数// this.$route.query.参数名 获取查询参数// this.$route.params.参数名 获取动态路由参数console.log(this.$route.params.words);} } /script两种传参方式的区别 查询参数传参比较适合传多个参数 ①跳转to/path?参数名值参数名2值 ②获取$routr.query.参数名动态路由传参优雅简洁传单个参数比较方便 ①配置动态路由path:/path/参数名 ②跳转topath/参数值 ③获取$route.params.参数名 动态路由参数可选符 问题配了路由 path:“/search/:words” 为什么按下面步骤操作回未匹配到组件显示空白 原因/search/:words 表示必须要传参数。如果不传参数也希望匹配可以加个可选符? 5.Vue路由 - 重定向 问题网页打开url默认是 / 路径未匹配到组件时会出现空白 说明重定向 → 匹配path后强制跳转path路径 语法{path:匹配路径redirect:重定向到的路径}redirect就是强制跳转到的路径 index.js // 创建了一个路由对象 const router new VueRouter({routes: [{ path: /, redirect: /home },{ path: /home, component: Home },{ path: /search/:words?, component: Search }] })6.Vue路由 - 404 作用当路径找不到匹配时给个提示页面(比如连接后面加了别的东西就是不存在的链接) 位置配在路由最后 语法path:*(任意路径) - 前面不匹配就命中最后这个*的意思是匹配所有的规则 index.js import NotFound from /views/NotFound // 创建了一个路由对象 const router new VueRouter({routes: [{ path: /, redirect: /home },{ path: /home, component: Home },{ path: /search/:words?, component: Search }{ path: *, component:NotFound}] })然后在views中新建一个NotFound.vue templatedivh1404 Not Found/h1/div /template7.Vue路由 - 模式设置 问题路由的路径看起来不自然 有#能否切成真正路径形式 hash路由默认 例如http://localhost:8080/#/homehistory路由(常用) 例如:http://localhost:8080/home(以后上线需要服务器端支持) 从默认模式切换到常用模式只要加mode:history就可以了 不带井号了 const router new VueRouter({// 注意一旦采用了 history 模式地址栏就没有 #需要后台配置访问规则mode: history,routes: [{ path: /, redirect: /home },{ path: /home, component: Home },{ name: search, path: /search/:words?, component: Search },{ path: *, component: NotFound }] })8.编程式导航 - 两种路由跳转 ①path路径跳转简易方便 home.vue script export default {name: FindMusic,methods: {goSearch () {//1. 通过路径的方式跳转(1) this.$router.push(路由路径) //[简写]this.$router.push(/search)(2) this.$router.push({ //[完整写法]path: 路由路径 })this.$router.push({path: /search})})}} } /scriptname命名路由跳转适合 path 路径长的场景 要先像上面圈出来的这里起名字然后下面的路由名与上面index.js中的对应才能起作用 Home.vue script export default {name: FindMusic,methods: {goSearch () {// 2. 通过命名路由的方式跳转 (需要给路由起名字) 适合长路径// this.$router.push({// name: 路由名// })this.$router.push({name: search})}} } /script9.编程式导航 - 路由传参 问题点击搜索按钮跳转需要传参如何实现 两种传参方式查询参数 动态路由传参 两种跳转方式对于两种传参方式都支持 path路径跳转传参 (query传参) 动态路由传参 index.js import Home from /views/Home import Search from /views/Search import NotFound from /views/NotFound import Vue from vue import VueRouter from vue-router Vue.use(VueRouter) // VueRouter插件初始化// 创建了一个路由对象 const router new VueRouter({// 注意一旦采用了 history 模式地址栏就没有 #需要后台配置访问规则mode: history,routes: [{ path: /, redirect: /home },{ path: /home, component: Home },{ name: search, path: /search/:words?, component: Search },{ path: *, component: NotFound }] })export default routerHome.vue templatediv classhomediv classlogo-box/divdiv classsearch-boxinput v-modelinpValue typetextbutton clickgoSearch搜索一下/button/divdiv classhot-link热门搜索router-link to/search/黑马程序员黑马程序员/router-linkrouter-link to/search/前端培训前端培训/router-linkrouter-link to/search/如何成为前端大牛如何成为前端大牛/router-link/div/div /templatescript export default {name: FindMusic,data () {return {inpValue: }},methods: {goSearch () {// 1. 通过路径的方式跳转// (1) this.$router.push(路由路径) [简写]// this.$router.push(路由路径?参数名参数值)// this.$router.push(/search)// this.$router.push(/search?key${this.inpValue}) //跟data做双向绑定// this.$router.push(/search/${this.inpValue})// (2) this.$router.push({ [完整写法] 更适合传参// path: 路由路径// query: {// 参数名: 参数值,// 参数名: 参数值// }// })// this.$router.push({// path: /search,// query: {// key: this.inpValue// }// })// this.$router.push({// path: /search/${this.inpValue}// })}} } /script Search.vue//通过搜索页接收 templatediv classsearchp搜索关键字: {{ $route.params.words }} /pp搜索结果: /pulli............./lili............./lili............./lili............./li/ul/div /templatescript export default {name: MyFriend,created () {// 在created中获取路由参数// this.$route.query.参数名 获取查询参数// this.$route.params.参数名 获取动态路由参数// console.log(this.$route.params.words);} }/scriptname命名路由跳转传参动态路由传参 Home.vue templatediv classhomediv classlogo-box/divdiv classsearch-boxinput v-modelinpValue typetextbutton clickgoSearch搜索一下/button/divdiv classhot-link热门搜索router-link to/search/黑马程序员黑马程序员/router-linkrouter-link to/search/前端培训前端培训/router-linkrouter-link to/search/如何成为前端大牛如何成为前端大牛/router-link/div/div /templatescript export default {name: FindMusic,data () {return {inpValue: }},methods: {goSearch () {// 2. 通过命名路由的方式跳转 (需要给路由起名字) 适合长路径// this.$router.push({// name: 路由名// query: { 参数名: 参数值 },//query传参// params: { 参数名: 参数值 }//动态传参// })this.$router.push({name: search,// query: {// key: this.inpValue// }params: {words: this.inpValue}})}} } /script Search.vue//通过搜索页接收 templatediv classsearchp搜索关键字: {{ $route.params.words }} /p//通过params.words接收p搜索结果: /pulli............./lili............./lili............./lili............./li/ul/div /template通过什么传参就用什么接收 console
http://www.dnsts.com.cn/news/149299.html

相关文章:

  • 什么二手车网站做最好济南营销型网站制作
  • 免费asp网站源码下载成都地铁建设分公司网站
  • 厦门网站优化推广国内app开发公司哪家好
  • 怎么管理购物网站南宁网站建设培训班
  • 能免费做微信群推广的网站给别人做网站的销售叫什么软件
  • seo网站推广 杭州南京科技网站设计多少钱
  • 中国建设银行网站网上银行企业免费网站建设哪里比较好
  • 招商网站平台宣城网站推广
  • 北京网站开发最专业的公司有限公司有哪些
  • 个人主页网站模板免费深圳专门做兼职的网站
  • 自己买域名可以做网站吗如何让网站做网页适配
  • 家具网站asp他达拉非片正确服用方法
  • 网站报301错误池州网站建设制作报价方案
  • 面向对象网站开发哪个网站做室内效果图厉害
  • 山东省聊城建设学校网站拐个娇妻做晚餐在哪个网站连载呢
  • 北京专业的网站建设加拿大搜索引擎
  • 网站挂马处理百度快照拉网线要多少钱
  • 大悟网站制作花钱做网站注意些什么
  • 深圳住房和建设局网站 龙华怎样创建app
  • 桂林什么公司做网站推广好网站域名怎么登陆
  • 品牌网站建设e小蝌蚪新乡做企业网站的公司
  • 珠海网站策划手把手教你实现电商网站开发
  • 常用的小企业网站建设营销型网站翻译
  • 芭乐站长统计 网站统计深圳南山做网站
  • 外贸 网站建设网站服务器作用
  • 南京网站高端软件项目管理案例教程第四版
  • 厦门seo网站西安企业100强
  • 番禺有经验的网站建设桂林网络设计
  • 邯山企业做网站推广网站建设 尚瑞科技
  • 深圳建站公司外围北海百度seo