Vue Material抽屉(如何在md-content里面显示file.vue)

Vue Material Drawer (how to display file.vue inside of md-content)

所以我正在尝试构建一个包含 4 个 files.vue(navigation.vue、Home.vue、something1.vue something2.vue)的网站,每个文件都有自己的自己的模板和风格。在 navigation.vue 我有一个临时抽屉,以便在每个文件 vue.js 上导航。
(临时抽屉的文档:https://vuematerial.io/components/drawer(我正在使用 Vue material)我使用了相同的代码)。

我的抽屉里有 md-toolbar、md-drawer 和 md-content 标签(它创建了我的导航菜单:

所以,我想知道他们是否可以将我的一个模板(通过单击 md-drawer 中的项目列表)加载到 md-content 标签中?

你可以使用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:

如果对您有帮助,欢迎为我的回答点个赞。希望这可以帮助! :)