Router view 是干嘛的? 如果说是 路由渲染出口 ,为什么我点了之后,整个页面还是变了?

clipboard.png
如图
我只是想在这个页面上点击link的时候,只在router-view上面渲染视图,而不是整个页面变了,
我看教程里面也是这么写的。。。为啥我的就有问题。。。

http://jsfiddle.net/yyx990803... 这是官方的

他就可以在把路由导航的组件渲染在routerview里面而不是整个页面跳转,。

<template>
  <div id="app">
 
      <div>
          <router-link to="/home"><span>sss</span></router-link>
          <router-link to="/manageApp">manageApp</router-link>
          <router-link to="/ManageConfig">ManageConfig</router-link>
      </div>

      <router-view ></router-view>
  </div>
</template>

<script>
import headNav from './components/nav.vue'
import sideNav from './components/side-nav.vue'
import myTable from './components/table.vue'
import Home  from './views/home.vue'


export default {
  name: 'app',
  components: {
    headNav,
    sideNav,
    myTable
  },
  data(){
    return {mas:[
      {text:"ID号",sortable:true,short:"id"},
      {text:"名称",sortable:true,short:"name"},
      {text:"昵称",sortable:true,short:"nickname"},
      {text:"邮箱",sortable:false,short:"email"},
      {text:"生日年月",sortable:true,short:"birthdate"},
      {text:"性别",sortable:false,short:"gender"},
      {text:"薪酬",sortable:true,short:"salary"},
      {text:"组号",sortable:false,short:"group_id"},
      {text:"创建日期",sortable:true,short:"created_at"},
      {text:"更新日期",sortable:true,short:"updated_at"}

    ],
    OperationPermission:{show:true,data:[1,1,1]}
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
    width:100%;
    height:50px;
}

.router-bottom {
    position: absolute;
    width:100%;
    height:600px;
    bottom: 0;
    background-color: #1d90e6;

}
</style>
阅读 3k
1 个回答

你代码没写完啊,四步:

  1. 定义组件(你引进来了)

  2. 定义路由策略(你没写)

    const routes = [
      { path: '/foo', component: Foo },
      { path: '/bar', component: Bar }
    ];
  3. 创建路由实例(你没写)

        const router = new VueRouter({
          routes
        });
  4. 挂载(你没写)

        const app = new Vue({
          router
        }).$mount('#app');
推荐问题