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

Vue极简入门

1.注册路由,如果是子路由,就加一个children

import Vue from 'vue'
import Router from 'vue-router'
import Main from '../views/Main.vue'
import Login from '../views/Login.vue'import UserProfile from "../views/user/Profile.vue"
import UserList from "../views/user/List.vue"Vue.use(Router)export default new Router({routes: [{path: '/login',name: 'login',component: Login},{path: '/main',name: 'main',component: Main,children:[{path:'/user/profile',component:UserProfile},{path:'/user/list',component:UserList},]}]
})

2.使用方法

显示的页面

显示的位置

<template><div><h1>Main</h1><router-link to="/user/profile">个人信息</router-link><router-link to="/user/list">用户列表</router-link><router-view></router-view></div>
</template><script>export default{name:"Main"}
</script><style scoped></style>

3.name 传组件名 params 传递参数 需要对象 v-bind 而后path接收数据

<template><div><h1>Main</h1><router-link :to="{name:'UserProfile',params:{id:1}}">个人信息</router-link><router-link to="/user/list">用户列表</router-link><router-view></router-view></div>
</template><script>export default{name:"Main"}
</script><style scoped></style>
import Vue from 'vue'
import Router from 'vue-router'
import Main from '../views/Main.vue'
import Login from '../views/Login.vue'import UserProfile from "../views/user/Profile.vue"
import UserList from "../views/user/List.vue"Vue.use(Router)export default new Router({routes: [{path: '/login',name: 'login',component: Login},{path: '/main',name: 'main',component: Main,children:[{path:'/user/profile/:id',name:'UserProfile',component:UserProfile},{path:'/user/list',component:UserList},]}]
})

3.1展示 {{ $route.params.id }}

<template><div><h1>个人信息</h1>{{ $route.params.id }}</div></template><script>
export default{name:"UserProfile"
}
</script><style scoped></style>

http://www.mrgr.cn/news/32995.html

相关文章:

  • 不要死磕技术,还是要产品化
  • 图像生成大模型 Imagen:重塑创意的未来
  • 排序----快速排序(快排)(递归版)
  • 构建高可用和高防御力的云服务架构第一部分:深入解析DDoS高防(1/5)
  • git submodule
  • 低代码可视化工具-uniapp页面跳转传参-代码生成器
  • 为什么喝酱酒会回甘?
  • T4—猴痘识别
  • Redis数据结构之哈希表
  • 【HTTP】请求“报头”,Referer 和 Cookie
  • 盘点3款.NetCore(C#)开源免费商城系统
  • C++(2)进阶语法
  • 十四、运算放大电路
  • 初中数学证明集锦之三角形内角和
  • 【小沐学GIS】blender导入OpenStreetMap城市建筑(blender-osm、blosm)
  • 结构体对齐、函数传参、库移植
  • Spring:统一结果私有属性造成的前端无法访问异常报错问题
  • 博客管理系统可行性分析报告
  • Elionix 电子束曝光系统
  • 分析redis实现分布式锁的思路