标签:const class temp view lin route username def this
路由
安装 vue-router
起步
<router-link to="/foo">Go to Foo</router-link> <router-link to="/bar">Go to Bar</router-link> <router-view></router-view>
const Foo = { template: ‘<div>foo</div>‘ } const Bar = { template: ‘<div>bar</div>‘ } const routes = [ { path: ‘/foo‘, component: Foo }, { path: ‘/bar‘, component: Bar } ] const router = new VueRouter({ routes // (缩写) 相当于 routes: routes }) const app = new Vue({ router }).$mount(‘#app‘)
通过this.$router访问路由器
export default { computed: { username () { return this.$route.params.username } }, methods: { goBack () { window.history.length > 1 ? this.$router.go(-1) : this.$router.push(‘/‘) } } }
标签:const class temp view lin route username def this
原文地址:https://www.cnblogs.com/sonwrain/p/10805511.html