前端学习(2173):动态路由的跳转
生活随笔
收集整理的這篇文章主要介紹了
前端学习(2173):动态路由的跳转
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
app.vue
<template><div id="app"><router-link to="/home">首頁</router-link><router-link to="/about">關(guān)于</router-link><router-link v-bind:to="'/user/'+userId">用戶</router-link><router-view></router-view></div> </template><script> export default {name: 'App',data(){return{userId:'userId'}},methods:{} } </script><style></style>?about.vue
<template> <div> <h2> 我是about </h2> <p>我是首頁內(nèi)容</p> </div> </template><script> export default{name:"Home" } </script><style scoped></style>User.vue
<template> <div> <h2> 我是user </h2> <p>我是首頁內(nèi)容</p> <h2>{{userId}}</h2> </div> </template><script> export default{name:"User",computed:{userId(){return this.$route.params.userId.abc}} } </script><style scoped></style>index.js
import VueRouter from 'vue-router' import Vue from 'vue' import Home from '../components/Home' import About from '../components/About' import User from '../components/User' Vue.use(VueRouter)const routes = [{path: '/',redirect: '/home'}, {path: '/home',component: Home},{path: '/about',component: About},{path: '/user/:userId',component: User},]//安裝插件 const router = new VueRouter({//配置之間的關(guān)系routes,mode: 'history',linkActiveClass: 'active' })export default router運(yùn)行結(jié)果
總結(jié)
以上是生活随笔為你收集整理的前端学习(2173):动态路由的跳转的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BackTrack 4 R2安装VMwa
- 下一篇: 前端学习(2321):angular环境