vue 实例化定义路由模板

 <div id="app">
    <router-view></router-view>
  </div>
  <template id="a">
    <div @click="link">hello</div>
  </template>
  <template id="b">
    <div>world</div>
  </template>
  const Home = Vue.extend({
    template: "#a",
    data: function() {
      return {}
    },
    methods: {
      link: function () {
        this.$router.push('/b')
      }
    }
  })
  const B = Vue.extend({
    template: "#b"
  })
  // 路由
  const routes = [
    {path:'/',component:Home},
    {path:'/b',component:B}
  ];
  const router = new VueRouter({
    routes
  })
  new Vue({
    el:"#app",
    router
  })

 

posted @ 2018-02-08 11:07  web前端kelly  阅读(296)  评论(0编辑  收藏  举报