码迷,mamicode.com
首页 > 其他好文 > 详细

Vue技术栈

时间:2019-05-03 18:18:53      阅读:200      评论:0      收藏:0      [点我收藏+]

标签: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(/)
    }
  }
}

 

Vue技术栈

标签:const   class   temp   view   lin   route   username   def   this   

原文地址:https://www.cnblogs.com/sonwrain/p/10805511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!