Vueutify导航抽屉-更改背景图像

时间:2019-05-03 06:32:42

标签: vue.js vuetify.js

嗨,我正在学习vuetify,我想更改从vuetify默认布局模板导入的导航抽屉的背景。

找到模板并在正式的vuetify文档中导入。


问题是我无法更改抽屉的背景并将其设置为图像

这是带抽屉的默认布局

<template>
  <v-app
    id="inspire"
    dark
  >
    <v-navigation-drawer
      v-model="drawer"
      fixed
      clipped
      app
    >
      <v-list dense>
        <v-list-tile v-for="item in items" :key="item.text" @click="">
          <v-list-tile-action>
            <v-icon>{{ item.icon }}</v-icon>
          </v-list-tile-action>
          <v-list-tile-content>
            <v-list-tile-title>
              {{ item.text }}
            </v-list-tile-title>
          </v-list-tile-content>
        </v-list-tile>
        <v-subheader class="mt-3 grey--text text--darken-1">SUBSCRIPTIONS</v-subheader>
        <v-list>
          <v-list-tile v-for="item in items2" :key="item.text" avatar @click="">
            <v-list-tile-avatar>
              <img :src="`https://randomuser.me/api/portraits/men/${item.picture}.jpg`" alt="">
            </v-list-tile-avatar>
            <v-list-tile-title v-text="item.text"></v-list-tile-title>
          </v-list-tile>
        </v-list>
        <v-list-tile class="mt-3" @click="">
          <v-list-tile-action>
            <v-icon color="grey darken-1">add_circle_outline</v-icon>
          </v-list-tile-action>
          <v-list-tile-title class="grey--text text--darken-1">Browse Channels</v-list-tile-title>
        </v-list-tile>
        <v-list-tile @click="">
          <v-list-tile-action>
            <v-icon color="grey darken-1">settings</v-icon>
          </v-list-tile-action>
          <v-list-tile-title class="grey--text text--darken-1">Manage Subscriptions</v-list-tile-title>
        </v-list-tile>
      </v-list>
    </v-navigation-drawer>
    <v-toolbar
      color="red"
      dense
      fixed
      clipped-left
      app
    >
      <v-toolbar-side-icon @click.stop="drawer = !drawer"></v-toolbar-side-icon>
      <v-icon class="mx-3">fab fa-youtube</v-icon>
      <v-toolbar-title class="mr-5 align-center">
        <span class="title">Youtube</span>
      </v-toolbar-title>
      <v-spacer></v-spacer>
      <v-layout row align-center style="max-width: 650px">
        <v-text-field
          :append-icon-cb="() => {}"
          placeholder="Search..."
          single-line
          append-icon="search"
          color="white"
          hide-details
        ></v-text-field>
      </v-layout>
    </v-toolbar>
    <v-content>
      <v-container fill-height>
        <v-layout justify-center align-center>
          <v-flex shrink>
            <v-tooltip right>
              <template v-slot:activator="{ on }">
                <v-btn :href="source" icon large target="_blank" v-on="on">
                  <v-icon large>code</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/YeRKwQ" target="_blank" v-on="on">
                  <v-icon large>mdi-codepen</v-icon>
                </v-btn>
              </template>
              <span>Codepen</span>
            </v-tooltip>
          </v-flex>
        </v-layout>
      </v-container>
    </v-content>
  </v-app>
</template>

<script>
  export default {
    data: () => ({
      drawer: null,
      items: [
        { icon: 'trending_up', text: 'Most Popular' },
        { icon: 'subscriptions', text: 'Subscriptions' },
        { icon: 'history', text: 'History' },
        { icon: 'featured_play_list', text: 'Playlists' },
        { icon: 'watch_later', text: 'Watch Later' }
      ],
      items2: [
        { picture: 28, text: 'Joseph' },
        { picture: 38, text: 'Apple' },
        { picture: 48, text: 'Xbox Ahoy' },
        { picture: 58, text: 'Nokia' },
        { picture: 78, text: 'MKBHD' }
      ]
    }),
    props: {
      source: String
    }
  }
</script>

我希望将背景图片应用于抽屉,例如:https://cdn.vuetifyjs.com/images/backgrounds/bg-2.jpg

我尝试在我的抽屉中使用src属性:

  <v-navigation-drawer
      v-model="drawer"
      fixed
      clipped
      app
      src="https://cdn.vuetifyjs.com/images/backgrounds/bg-2.jpg"
    >

但这是行不通的,我也尝试在Div中包装抽屉,并使用具有范围的CSS访问类,但没有成功。

在官方Vuetify Codepen中有一个用于抽屉的背景就绪组件:https://codepen.io/pen/?&editable=true&editors=101 显示使用src属性。 但是由于某种原因,它不适用于本示例。

1 个答案:

答案 0 :(得分:2)

Vuetify v1

Codepen

src属性在v1 Navigation drawer docs中不存在,因此可能的解决方法是将v-img放在抽屉中的高度为100%:

<v-navigation-drawer>
  <v-img
    src="https://cdn.vuetifyjs.com/images/backgrounds/bg-2.jpg"  
    height="100%"
  >


Vuetify v2

Codepen

在Vuetify v2 Navigation drawer docs中,它具有src属性,因此其工作方式如下:

<v-navigation-drawer src="https://cdn.vuetifyjs.com/images/backgrounds/bg-2.jpg">