Vue【从无到有从有到无】【F1】路由 【待续】

1.传递参数

/** 定义路由 **/
import Vue from 'vue'
import Router from 'vue-router'
import Test from '../view/Test'

Vue.use(Router)

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

 

/** url 为隐藏参数内容 **/
/** http://localhost:8004/#/Test **/
/** 跳转前 **/
this.$router.push({
    name: 'Test',
    params: {
       name: 'test'
    }
})

/** 跳转到的vue **/
console.log(this.$route.params.name)



/** url 为显示参数内容 **/
/** http://localhost:8004/#/Test?name=test **/
/** 跳转前 **/
this.$router.push({
    path: '/Test',
    query: {
       name: 'test'
    }
})

/** 跳转到的vue **/
console.log(this.$route.query.name)

 

你可能感兴趣的:(Vue)