【问题标题】:Router to action with using Vue.js使用 Vue.js 进行操作的路由器
【发布时间】:2020-06-20 18:36:32
【问题描述】:

我正在学习 vue.js,我正在使用 Vuetify 官方网站上的这段代码来练习预先制作的布局。我该怎么做哟 我的意思是,当您按下侧菜单上的某个按钮时,无需刷新页面即可将信息加载到其他地方

提前谢谢...

<template>

  <v-app id="inspire">

    <v-navigation-drawer

      v-model="drawer"

      :clipped="$vuetify.breakpoint.lgAndUp"

      app

    >

      <v-list dense>

        <template v-for="item in items">

          <v-row

            v-if="item.heading"

            :key="item.heading"

            align="center"

          >

            <v-col cols="6">

              <v-subheader v-if="item.heading">

                {{ item.heading }}

              </v-subheader>

            </v-col>

            <v-col

              cols="6"

              class="text-center"

            >

              <a

                href="#!"

                class="body-2 black--text"

              >EDIT</a>

            </v-col>

          </v-row>

          <v-list-group

            v-else-if="item.children"

            :key="item.text"

            v-model="item.model"

            :prepend-icon="item.model ? item.icon : item['icon-alt']"

            append-icon=""

          >

            <template v-slot:activator>

              <v-list-item-content>

                <v-list-item-title>

                  {{ item.text }}

                </v-list-item-title>

              </v-list-item-content>

            </template>

            <v-list-item

              v-for="(child, i) in item.children"

              :key="i"

              link

            >

              <v-list-item-action v-if="child.icon">

                <v-icon>{{ child.icon }}</v-icon>

              </v-list-item-action>

              <v-list-item-content>

                <v-list-item-title>

                  {{ child.text }}

                </v-list-item-title>

              </v-list-item-content>

            </v-list-item>

          </v-list-group>

          <v-list-item

            v-else

            :key="item.text"

            link

          >

            <v-list-item-action>

              <v-icon>{{ item.icon }}</v-icon>

            </v-list-item-action>

            <v-list-item-content>

              <v-list-item-title>

                {{ item.text }}

              </v-list-item-title>

            </v-list-item-content>

          </v-list-item>

        </template>

      </v-list>

    </v-navigation-drawer>



    <v-app-bar

      :clipped-left="$vuetify.breakpoint.lgAndUp"

      app

      color="blue darken-3"

      dark

    >

      <v-app-bar-nav-icon @click.stop="drawer = !drawer" />

      <v-toolbar-title

        style="width: 300px"

        class="ml-0 pl-4"

      >

        <span class="hidden-sm-and-down">Google Contacts</span>

      </v-toolbar-title>

      <v-text-field

        flat

        solo-inverted

        hide-details

        prepend-inner-icon="mdi-magnify"

        label="Search"

        class="hidden-sm-and-down"

      />

      <v-spacer />

      <v-btn icon>

        <v-icon>mdi-apps</v-icon>

      </v-btn>

      <v-btn icon>

        <v-icon>mdi-bell</v-icon>

      </v-btn>

      <v-btn

        icon

        large

      >

        <v-avatar

          size="32px"

          item

        >

          <v-img

            src="https://cdn.vuetifyjs.com/images/logos/logo.svg"

            alt="Vuetify"

          /></v-avatar>

      </v-btn>

    </v-app-bar>

    <v-content>

      <v-container

        class="fill-height"

        fluid

      >

        <v-row

          align="center"

          justify="center"

        >

          <v-tooltip right>

            <template v-slot:activator="{ on }">

              <v-btn

                :href="source"

                icon

                large

                target="_blank"

                v-on="on"

              >

                <v-icon large>mdi-code-tags</v-icon>

              </v-btn>

            </template>

            <span>Source</span>

          </v-tooltip>

          <v-tooltip right>

            <template v-slot:activator="{ on }">

              <v-btn

                icon

                large

                href="https://codepen.io/johnjleider/pen/MNYLdL"

                target="_blank"

                v-on="on"

              >

                <v-icon large>mdi-codepen</v-icon>

              </v-btn>

            </template>

            <span>Codepen</span>

          </v-tooltip>

        </v-row>

      </v-container>

    </v-content>

    <v-btn

      bottom

      color="pink"

      dark

      fab

      fixed

      right

      @click="dialog = !dialog"

    >

      <v-icon>mdi-plus</v-icon>

    </v-btn>

    <v-dialog

      v-model="dialog"

      width="800px"

    >

      <v-card>

        <v-card-title class="grey darken-2">

          Create contact

        </v-card-title>

        <v-container>

          <v-row class="mx-2">

            <v-col

              class="align-center justify-space-between"

              cols="12"

            >

              <v-row

                align="center"

                class="mr-0"

              >

                <v-avatar

                  size="40px"

                  class="mx-3"

                >

                  <img

                    src="//ssl.gstatic.com/s2/oz/images/sge/grey_silhouette.png"

                    alt=""

                  >

                </v-avatar>

                <v-text-field

                  placeholder="Name"

                />

              </v-row>

            </v-col>

            <v-col cols="6">

              <v-text-field

                prepend-icon="mdi-account-card-details-outline"

                placeholder="Company"

              />

            </v-col>

            <v-col cols="6">

              <v-text-field

                placeholder="Job title"

              />

            </v-col>

            <v-col cols="12">

              <v-text-field

                prepend-icon="mdi-mail"

                placeholder="Email"

              />

            </v-col>

            <v-col cols="12">

              <v-text-field

                type="tel"

                prepend-icon="mdi-phone"

                placeholder="(000) 000 - 0000"

              />

            </v-col>

            <v-col cols="12">

              <v-text-field

                prepend-icon="mdi-text"

                placeholder="Notes"

              />

            </v-col>

          </v-row>

        </v-container>

        <v-card-actions>

          <v-btn

            text

            color="primary"

          >More</v-btn>

          <v-spacer />

          <v-btn

            text

            color="primary"

            @click="dialog = false"

          >Cancel</v-btn>

          <v-btn

            text

            @click="dialog = false"

          >Save</v-btn>

        </v-card-actions>

      </v-card>

    </v-dialog>

  </v-app>

</template>



<script>

  export default {

    props: {

      source: String,

    },

    data: () => ({

      dialog: false,

      drawer: null,

      items: [

        { icon: 'mdi-contacts', text: 'Contacts' },

        { icon: 'mdi-history', text: 'Frequently contacted' },

        { icon: 'mdi-content-copy', text: 'Duplicates' },

        {

          icon: 'mdi-chevron-up',

          'icon-alt': 'mdi-chevron-down',

          text: 'Labels',

          model: true,

          children: [

            { icon: 'mdi-plus', text: 'Create label' },

          ],

        },

        {

          icon: 'mdi-chevron-up',

          'icon-alt': 'mdi-chevron-down',

          text: 'More',

          model: false,

          children: [

            { text: 'Import' },

            { text: 'Export' },

            { text: 'Print' },

            { text: 'Undo changes' },

            { text: 'Other contacts' },

          ],

        },

        { icon: 'mdi-settings', text: 'Settings' },

        { icon: 'mdi-message', text: 'Send feedback' },

        { icon: 'mdi-help-circle', text: 'Help' },

        { icon: 'mdi-cellphone-link', text: 'App downloads' },

        { icon: 'mdi-keyboard', text: 'Go to the old version' },

      ],

    }),

  }

</script>

【问题讨论】:

    标签: vue.js routes vuetify.js


    【解决方案1】:

    你要找的是 vue-router (npm i vue-router),然后如下设置你的 main.js 页面

    import Vue from 'vue'
    import App from './App.vue'
    import Home from './components/Home.vue'
    import About from './components/About.vue'
    import Contact from './components/Contact.vue'
    
    import vuetify from './plugins/vuetify';
    Vue.config.productionTip = false;
    
    import VueRouter from 'vue-router'
    Vue.use(VueRouter)
    const router = new VueRouter({
      mode: 'history',
      routes: [
        { name: 'home', path: '/', component: Home},
        { name: 'about', path: '/about', component: About},
        { name: 'contact', path: '/contact', component: Contact}
      ]
    })
    
    new Vue({
      vuetify,
      router
      render: h => h(App)
    }).$mount('#app')
    

    而在 App.vue 中你需要加载 &lt;router-view&gt;

    <template>
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </template>
    <script>
    export default {
      name: "App"
    };
    </script>
    

    您可以简单地添加一些 href &lt;a href="/about"&gt;About&lt;/a&gt; 来在页面之间导航,或者您可以在 v-btn 中使用 :to 属性,如果您有其他一些没有 :to 属性的 vuetify 元素,那么您可以换行&lt;router-link&gt;中的元素

    <router-link :to="/about">
      <span>About</span>
    </router-link>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 2020-05-08
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 2023-02-22
      相关资源
      最近更新 更多