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

编程自学免费网站江苏省城乡建设厅建设网站

编程自学免费网站,江苏省城乡建设厅建设网站,制作图片下载什么软件,用别的公司域名做网站Vue Router 是 Vue.js 官方的路由管理器。Vue Router 基于路由和组件的映射关系#xff0c;监听页面路径的变化#xff0c;渲染对应的组件。 安装#xff1a; npm install vue-router。 基本使用#xff1a; // src/router/index.js import {createRouter, createWebHa…Vue Router 是 Vue.js 官方的路由管理器。Vue Router 基于路由和组件的映射关系监听页面路径的变化渲染对应的组件。 安装 npm install vue-router。 基本使用 // src/router/index.js import {createRouter, createWebHashHistory} from vue-routerimport Home from ../components/Home.vue import About from ../components/About.vue// 1. 创建路由对象 const router createRouter({// 配置路由映射关系一个路径对应一个组件routes: [{path: /, redirect: /home}, // 如果路径是 /重定向到 /home {path: /home, component: Home},{path: /about, component: About}],// 配置采用的模式。createWebHashHistory 是 hash 模式createWebHistory 是 history 模式history: createWebHashHistory(), })export default router// src/main.js import { createApp } from vue import App from ./App.vue import router from ./routerconst app createApp(App) // 2. 注册路由对象 app.use(router) app.mount(#app)可以使用 Vue Router 提供的 router-link 组件实现路径跳转。 // src/App.vue。 template!-- 3. 使用 Vue Router 提供的 router-link 组件实现路径跳转 --router-link to/home首页/router-linkrouter-link to/about关于/router-link!-- 4. 路径匹配到的组件将会显示在 router-view 这个占位组件处 --router-view/router-view /templatescript setup /scriptstyle scoped /style 也可以通过代码逻辑实现路径跳转。 // src/App.vue templatedivspan clickhandleHomeNav首页/spanspan clickhandleAboutNav关于/span/div!-- 4. 路径匹配到的组件将会显示在 router-view 这个占位组件处 --router-view/router-view /templatescript setup // 3. 通过代码逻辑实现路径跳转 import { useRouter } from vue-router const router useRouter() const handleHomeNav () {router.push(/home) } const handleAboutNav () {router.push({path: /about}) // router 对象还有 replace、forward、back、go 等方法 } /scriptstyle scoped /style router-link 组件 router-link用于创建导航链接。属性有 to用于指定要跳转的路径。属性值是一个字符串或者对象。router-link to/home首页/router-link router-link to{path: /home}首页/router-linkreplace设置 replace 属性的化路径跳转时将会直接替换掉旧路径旧路径不会进入历史列表回退页面的话无法回退到旧页面。active-class设置激活 a 元素后应用的 class 属性名称。默认是 router-link-active。exact-active-class链接精准激活时应用于 a 元素的 class 属性名称。默认是 router-link-exact-active。 嵌套路由 通过 children 配置嵌套路由。 // src/router/index.js import {createRouter, createWebHashHistory} from vue-routerimport User from ../components/User.vue import UserProfile from ../components/UserProfile.vue import UserPosts from /components/UserPosts.vueconst router createRouter({routes: [{path: /user/:id, // 以 / 开头的嵌套路径将被视为根路径component: User,// 1. 通过 children 配置嵌套路由children: [{// 当路径匹配到 /user/:id/profile就会渲染 UserProfile 组件到 User 组件的 router-view 内部path: profile,component: UserProfile,},{// 当路径匹配到 /user/:id/posts就会渲染 UserPosts 组件到 User 组件的 router-view 内部path: posts,component: UserPosts,},]},],history: createWebHashHistory(), })export default router// src/App.vue template!-- 2. 顶层的 router-view 渲染顶层路由匹配的组件。User 组件将会被渲染到这个位置 --router-view/router-view /templatescript setup /scriptstyle scoped /style // src/components/User.vue templatedivUser{{ $route.params.id }}/div!-- 3. 一个被渲染的组件也可以包含自己嵌套的 router-view。UserProfile 和 UserPosts 组件将会被渲染到这个位置 --router-view/router-view /templatescript setup /scriptstyle scoped /style 动态路由 通过 :名称 的路径参数来配置动态路由。路径是动态的路径参数的部分在进行路由匹配时可以变化。 // src/router/index.js import {createRouter, createWebHashHistory} from vue-routerimport User from /components/User.vueconst router createRouter({routes: [// 1. 通过 :名称 配置动态路由。路径是动态的路径参数的部分在进行路由匹配时是可以变化的{path: /user/:id, component: User}],history: createWebHashHistory(), })export default router// src/App.vue template!-- 2. 无论是 user/123 还是 user/456都可以匹配得上 --router-link to/user/123用户123/router-linkrouter-link to/user/456用户456/router-linkrouter-view/router-view /templatescript setup /scriptstyle scoped /style //src/components/User.vue template!-- 3. 在 template 模板中获取动态路由的值 --divUser{{ $route.params.id }}/div /templatescript setup // 3. 在 Options API 中获取动态路由的值 // this.$route.params.id// 3. 在 Composition API 中获取动态路由的值。通过 useRoute() Hook 函数获取 import { useRoute } from vue-router const route useRoute() console.log(route.params.id) /scriptstyle scoped /style 通过动态路由实现 NotFound 对于没有匹配到的路由通常会匹配到某个固定的页面例如 NotFound 页面。可以编写一个动态路由用于匹配所有的页面。 // // src/router/index.js import {createRouter, createWebHashHistory} from vue-routerimport NotFound from /components/NotFound .vueconst router createRouter({routes: [// 1. 如果匹配到任何一个不存在的路径那么就匹配 NotFound 组件。{path:/:pathMatch(.*), component: NotFound }],history: createWebHashHistory(), })export default router//src/components/NotFound .vue template!-- 2. 获取当前的路径参数 --divNotFound{{ $route.params.pathMatch }}/div /templatescript setup /scriptstyle scoped /style 如果配置路由时在 /:pathMatch(.*) 后面再加一个 *变成 {path:/:pathMatch(.*)*, component: NotFound }那么在获取路径参数时会以 / 为分隔符将路径参数解析为数组。 动态管理路由 路由传参 可以通过动态路由的方式传递简单参数在组件中通过 $route.params 的方法获取。也可以在通过代码逻辑实现路径跳转时通过 query 传递参数在组件中通过 $route.query 获取。const handleAboutNav () {router.push({path: /about,// 1. 传递参数query: {name: Lee,age: 18,}}) }// 获取参数 import { useRoute } from vue-router const route useRoute() console.log(route.query.name)路由懒加载 // src/router/index.js import {createRouter, createWebHashHistory} from vue-router// 通过使用 import() 函数进行路由懒加载。打包时会进行分包处理就可以在需要的时候再根据路径下载对应的组件代码 const Home () import(../components/Home.vue) const About () import(../components/About.vue)const router createRouter({routes: [{path: /, redirect: /home}, {path: /home, component: Home},{path: /about, component: About}],history: createWebHashHistory(), })export default router
http://www.w-s-a.com/news/561484/

相关文章:

  • 如何做网站的后台管理石家庄seo关键词排名
  • 给自己公司做个网站山东做外贸网站的公司
  • 张家港网站建设培训江苏省建设工程网站系统
  • html个人网站桂林建站
  • 湛江网站优化快速排名wordpress文章页面宽度
  • 自己建网站怎么弄唯品会一家专门做特卖的网站
  • 做文化传播公司网站做搜狗pc网站点
  • 免费的黄冈网站有哪些平台可以聊天呢要查询一个网站在什么公司做的推广怎么查
  • 凡客建站登录入口网站建设先进部门评选标准
  • 响应式设计 手机网站政务中心建设网站
  • 如何做卖衣服的网站网站登录接口怎么做
  • 网站源码下载了属于侵权吗499全包网站建设
  • 怎样创建网站信息平台网络推广官网首页
  • 网站建设的课程网站 逻辑结构
  • 开通企业网站搬瓦工暗转wordpress
  • 成都网站建设有名的公司怎么做出有品牌感的网站
  • 中国网站的建设淘宝数据网站开发
  • 深圳建站网站模板wordpress 文章最长
  • 服务器建立网站建网站做seo
  • 帮人做彩票网站支付接口网上请人做软件的网站
  • 万全网站建设wl17581做旅游广告在哪个网站做效果好
  • 钢城网站建设安徽省住房和城乡建设厅网站
  • 协会网站建设方案大良营销网站建设好么
  • 网站引导页一般是什么格式网页设计师的应聘岗位
  • 构建网站空间网站开发与维护招聘
  • 网站建设的网页怎么做番禺网站开发哪家强
  • 网站开发是程序员吗百度网盘下载电脑版官方下载
  • 中国电力建设集团网站杭州网站运营
  • 大气网站模板下载效果好的网站建设公
  • 住房和城乡建设部网站打不开重庆市建设工程信息网官网30系统