Vue材质抽屉(如何在md-content内部显示file.vue)

时间:2019-02-09 00:13:52

标签: css vue.js vue-material

因此,我正在尝试构建一个包含4个文件的网站。vue(navigation.vue,Home.vue,something1.vue something2.vue)每个文件都有其自己的模板和样式。在navigation.vue内部,我有一个临时抽屉,以便在每个文件vue上导航。
(临时抽屉的文档:https://vuematerial.io/components/drawer(我使用的是Vue材料),我使用了相同的代码)。

在我的抽屉里,我确实有md工具栏,md抽屉和md内容标签(通过它创建了我的导航菜单:

所以,我想知道它们是否是一种将我的模板(通过单击md-drawer中的项目列表)加载到md-content标记中的方法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用vue-router。要安装vue-router,请转到您的根目录,然后在终端中键入以下内容:

npm install vue-router

App.vue或您要呈现.vue文件的示例代码段:

<template>
<v-app>
  <!-- route outlet -->
  <!-- component matched by the route will render here -->
  <router-view></router-view>
</v-app>
</template>

routes.js文件或您将在其中注册路线的示例代码段:

// 0. If using a module system (e.g. via vue-cli), import Vue and VueRouter
// and then call `Vue.use(VueRouter)`.

// 1. Define route components.
// These can be imported from other files
import Home from './path/to/Home';
import Something1 from './path/to/Something1';
import Something2 from './path/to/Something2';

const routes = [
  {
        path: '/',
        name: 'Home',
        component: Home
    },
    {
        path: '/something1',
        name: 'Something1',
        component: Something1
    },
    {
        path: '/something2',
        name: 'Something2',
        component: Something2
    },
]

// 3. Create the router instance and pass the `routes` option
const router = new VueRouter({
  routes // short for `routes: routes`
})

// 4. Create and mount the root instance.
// Make sure to inject the router with the router option to make the
// whole app router-aware.
const app = new Vue({
  router
}).$mount('#app')

// Now the app has started!

您必须将每个md选项都放在vue-router-link中,如下所示:

    <md-drawer :md-active.sync="showNavigation">
      <md-toolbar class="md-transparent" md-elevation="0">
        <span class="md-title">My App name</span>
      </md-toolbar>

      <md-list>
        <md-list-item>
          <!-- use router-link component for navigation. -->
          <!-- specify the link by passing the `to` prop. -->
          <!-- replace "/foo" and "/bar" with your route path (e.g., "/home", "/something1", "/something2") -->
          <router-link to="/foo">
            <md-icon>move_to_inbox</md-icon>
            <span class="md-list-item-text">Inbox</span>
          </router-link>
        </md-list-item>

        <md-list-item>
          <router-link to="/bar">
            <md-icon>send</md-icon>
            <span class="md-list-item-text">Sent Mail</span>
          </router-link>
        </md-list-item>

        <md-list-item>
          <router-link to="/foo">
            <md-icon>delete</md-icon>
            <span class="md-list-item-text">Trash</span>
          </router-link>
        </md-list-item>

        <md-list-item>
          <router-link to="/bar">
            <md-icon>error</md-icon>
            <span class="md-list-item-text">Spam</span>
          </router-link>
          </md-list-item>
      </md-list>
    </md-drawer>

您可以在此处了解有关vue-router的更多信息:Vue Router Documentation

如果有帮助,请随时提出我的答案。希望这可以帮助! :)