VUE vuerouter的介绍的介绍 基于vuerouter实现路由跳转以及路由跳转的时候携带参数传递

1.VueRouter(路由)

2.SPA

首页我们知道Vue是单页面应用程序,所谓单页面应用程序在一个完整的应用或站点中,只有一个完整的HTML页面,这个页面有一个容器,可以把需要的代码插入到该容器中

3.SPA 工作原理

例如:http://localhost:8081/#/test
(1)根据地址栏中URL解析完的页面index.html,加载index.html
(2)根据地址栏解析#后的路由地址:test;根据路由地址,去当前应用的配置中找路由地址配置对象去查找对应的模块页面地址,发起异步请求加载该页面地址 (3)把请求的数据加载到指定的容器中

4.SPA的实现步骤

(1)使用Vue-router的前提是已经引入vue-router.js
(2)显示组件
<template>
  <div id="app">
    <router-view/>
  </div>
</template>

(3)创建Vue 组件

(4)配置信息 (配置路由词典)

 const  myroutes= [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/test',
      name: 'test',
      component: test
    }
  ]

(5)创建路由表对象

const Router =  new VueRouter({
routes:  myroutes
})

(6)在Vue对象添加现在应用路由表对象

new Vue({el:'#app',router:newrouter})
在Vue中也可以这样写:
router->index.js
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import test from '@/components/test'
Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/test',
      name: 'test',
      component: test
    }
  ]
})

main,js

import Vue from 'vue'
import App from './App'
import router from './router'
// import router from '../src/router/index.js'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

5.路由跳转

使用路由切换的提前是已经添加到路由词典中

(1)使用router-link
<router-link to='/test'>跳转路由test</router-link>

(2)使用js

<button @click="jump">路由</button>
  jump(){
    this.$router.push('/test')
  },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值