如何修复一个被卡片遮挡的Vue3/Vuetify3日期选择器?

huangapple go评论46阅读模式
英文:

How to fix a Vue3/Vuetify3 datepicker that's hidden behind a card?

问题

My project uses Vue3 and Vuetify3.
And I want to add a datepicker to my code. But I didn't find one in Vuetify3.

I create my project with:

vue create vuetify
cd [project dir]
yarn add @vuepic/vue-datepicker

My component code is:

<template>
  <v-card class="mt-16">
    <v-card-title>Crop Management</v-card-title>

    <v-card-text>
      <v-row>
        <v-col>
          <v-select
            label="Crop"
            :items="crop_list"
            variant="outlined"
          ></v-select>
        </v-col>

        <v-col>
          <vue-date-picker></vue-date-picker>
        </v-col>
      </v-row>
    </v-card-text>
  </v-card>
</template>

<script>
import VueDatePicker from '@vuepic/vue-datepicker';
import '@vuepic/vue-datepicker/dist/main.css';
export default {
  name: "CropManagement",
  components: {
    VueDatePicker
  },
  data() {
    return {
      crop_list: [
        "Strawberry",
        "Alfalfa"
      ],
    };
  },
};
</script>

<style scoped></style>

screenshot

But my datepicker is under the card.
How can I solve this problem?

I tried changing z-index, but it didn't work.

英文:

My project uses Vue3 and Vuetify3.
And I want to add a datepicker to my code. But I didn't find one in vuetify3.

I create my project with:

vue create vuetify
cd [project dir]
yarn add @vuepic/vue-datepicker

My component code is:

&lt;template&gt;
  &lt;v-card class=&quot;mt-16&quot;&gt;
    &lt;v-card-title&gt;Crop Management&lt;/v-card-title&gt;

    &lt;v-card-text&gt;
      &lt;v-row&gt;
        &lt;v-col&gt;
          &lt;v-select
            label=&quot;Crop&quot;
            :items=&quot;crop_list&quot;
            variant=&quot;outlined&quot;
          &gt;&lt;/v-select&gt;
        &lt;/v-col&gt;

        &lt;v-col&gt;
          &lt;vue-date-picker&gt;&lt;/vue-date-picker&gt;
        &lt;/v-col&gt;
      &lt;/v-row&gt;
    &lt;/v-card-text&gt;
  &lt;/v-card&gt;
&lt;/template&gt;

&lt;script&gt;
import VueDatePicker from &#39;@vuepic/vue-datepicker&#39;;
import &#39;@vuepic/vue-datepicker/dist/main.css&#39;
export default {
  name: &quot;CropManagement&quot;,
  components: {
    VueDatePicker
  },
  data() {
    return {
      crop_list: [
        &quot;Strawberry&quot;,
        &quot;Alfalfa&quot;
      ],
    };
  },
};
&lt;/script&gt;

&lt;style scoped&gt;&lt;/style&gt;

screenshot

But my datepicker is under the card.
How can I solve this problem?

I tried change z-index, but isn't work.

答案1

得分: 1

The datapicker attaches to the input element, but then gets clipped by the card, so it is not visible.

Setting the teleport property fixes the issue:

&lt;vue-date-picker
  :teleport=&quot;true&quot;
&gt;&lt;/vue-date-picker&gt;

From the documentation:
> Use teleport to position the datepicker menu. This is useful if you have hidden overflow on the parent HTML element where the menu is not showing in full. If you just set the value to true, the menu will be placed on body

Here it is in a snippet:

<!-- begin snippet: js hide: true console: false babel: false -->

<!-- language: lang-js -->

const { createApp, ref } = Vue;
const { createVuetify } = Vuetify
const vuetify = createVuetify()
const app = {
components: {'vue-date-picker': VueDatePicker},
data() {
return {
teleport: true,
};
},
}
createApp(app).use(vuetify).mount('#app')

<!-- language: lang-html -->

<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/vuetify@3/dist/vuetify.min.css" />
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href=" https://cdn.jsdelivr.net/npm/@vuepic/vue-datepicker@5.1.2/dist/main.min.css " rel="stylesheet">
<div id="app">
<v-app>
<v-main>
<v-card>
<v-card-title>Crop Management</v-card-title>

&lt;v-card-text&gt;
&lt;v-row&gt;
&lt;v-col&gt;
&lt;v-switch
v-model=&quot;teleport&quot;
label=&quot;Use teleport&quot;
&gt;&lt;/v-switch&gt;
&lt;/v-col&gt;
&lt;v-col&gt;
&lt;vue-date-picker
:teleport=&quot;teleport&quot;
&gt;&lt;/vue-date-picker&gt;
&lt;/v-col&gt;
&lt;/v-row&gt;
&lt;/v-card-text&gt;

</v-card>
</v-main>
</v-app>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@3/dist/vuetify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@vuepic/vue-datepicker@5.1.2/dist/vue-datepicker.iife.js"></script>

<!-- end snippet -->

英文:

The datapicker attaches to the input element, but then gets clipped by the card, so it is not visible.

Setting the teleport property fixes the issue:

&lt;vue-date-picker
  :teleport=&quot;true&quot;
&gt;&lt;/vue-date-picker&gt;

From the documentation:
> Use teleport to position the datepicker menu. This is useful if you have hidden overflow on the parent HTML element where the menu is not showing in full. If you just set the value to true, the menu will be placed on body

Here it is in a snippet:

<!-- begin snippet: js hide: true console: false babel: false -->

<!-- language: lang-js -->

const { createApp, ref } = Vue;
const { createVuetify } = Vuetify
const vuetify = createVuetify()
const app = {
components: {&#39;vue-date-picker&#39;: VueDatePicker},
data() {
return {
teleport: true,
};
},
}
createApp(app).use(vuetify).mount(&#39;#app&#39;)

<!-- language: lang-html -->

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://cdn.jsdelivr.net/npm/vuetify@3/dist/vuetify.min.css&quot; /&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;link href=&quot; https://cdn.jsdelivr.net/npm/@vuepic/vue-datepicker@5.1.2/dist/main.min.css &quot; rel=&quot;stylesheet&quot;&gt;
&lt;div id=&quot;app&quot;&gt;
&lt;v-app&gt;
&lt;v-main&gt;
&lt;v-card&gt;
&lt;v-card-title&gt;Crop Management&lt;/v-card-title&gt;
&lt;v-card-text&gt;
&lt;v-row&gt;
&lt;v-col&gt;
&lt;v-switch
v-model=&quot;teleport&quot;
label=&quot;Use teleport&quot;
&gt;&lt;/v-switch&gt;
&lt;/v-col&gt;
&lt;v-col&gt;
&lt;vue-date-picker
:teleport=&quot;teleport&quot;
&gt;&lt;/vue-date-picker&gt;
&lt;/v-col&gt;
&lt;/v-row&gt;
&lt;/v-card-text&gt;
&lt;/v-card&gt;
&lt;/v-main&gt;
&lt;/v-app&gt;
&lt;/div&gt;
&lt;script src=&quot;https://unpkg.com/vue@3/dist/vue.global.prod.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@3/dist/vuetify.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/@vuepic/vue-datepicker@5.1.2/dist/vue-datepicker.iife.js&quot;&gt;&lt;/script&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月21日 23:29:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定