Updating Vuetify Class on the Fly

I am facing an issue with styling a Vuetify dialog dynamically. Despite trying computed style bindings, CSS variables, and direct input of styles, the default v-dialog stylings are not being overwritten. How can I achieve dynamic styling on a Vuetify component?

Here is the code for my dialog:

<template>
  <v-dialog 
    v-model="dialog" 
    max-width="350px"
    persistent
    hide-overlay
    style="{position: absolute; bottom: 0px;}"
  >        
  <div class="arrow-up mb-n1 ml-1"></div>
  <v-card>
    <v-container>
    <v-card-text>
    <v-row>
      <v-col 
        cols="12"
        align="start"
      >
        <p class="text-subtitle-1">
        Always best to start at the beginning, let's pull your products first.</p>
      </v-col>
    </v-row>
    </v-card-text>
      
      <v-card-actions class="mt-n8">
        <v-btn
          color="#68007d"
          text
          @click="goToImportMethod"
        >
          NEXT
        </v-btn>
        <v-btn
          color="#616161"
          text
          @click="closeEverything"
        >
          CLOSE
        </v-btn>
      </v-card-actions>
    </v-container>
  </v-card>
  </v-dialog>
</template>

I have attempted using a computed property like this:

  <v-dialog 
    v-model="dialog" 
    max-width="350px"
    persistent
    hide-overlay
    :style="myStyle"
  >

With the following computation function:

computed: {
  myStyle() {
    return {
      bottom: '0px',
      left: '150px',
      position: 'absolute'
    }
  }
},

I also tried incorporating variables within the class itself as shown below:

>>> .v-dialog {
  box-shadow: none;
  overflow: visible;
  bottom: var(--bottom);
  left: 150px;
  position: absolute;
}

using a simple data property:

data () {
  return {
    dialog: true,
    bottom: '0px',
  }
},

However, only statically overwriting the class seems to provide any results:

>>> .v-dialog {
  box-shadow: none;
  overflow: visible;
  bottom: 0px;
  left: 150px;
  position: absolute;
}

Answer №1

The v-modal generates an overlay that encloses the real dialogue content. If you need to send properties like :style to the container, utilize the :content-properties attribute:

<v-modal
  :content-properties="{style: myStyle}
  ...

If your goal is just to apply CSS classes to the container, the :content-class property can be used.

Check out this code snippet:

const { createApp, ref } = Vue;
const { createVuetify } = Vuetify
const vuetify = createVuetify()
const app = {
  setup(){
    const styles = {
      bottom: '0px',
      left: '0px',
      position: 'absolute',
    }
    
    return {
      dialog: ref(true),
      styles
    }
  }

}
createApp(app).use(vuetify).mount('#app')
<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/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="53353c3d2713667d2b">[email protected]</a>/css/materialdesignicons.min.css" rel="stylesheet">
<div id="app">
  <v-app>
    <v-main>
      <v-modal v-model="dialog" max-width="350px" persistent hide-overlay :content-properties="{style: styles}">
        <div class="arrow-up mb-n1 ml-1"></div>
        <v-card>
          <v-container>
            <v-card-text>
              <v-row>
                <v-col cols="12" align="start">
                  <p class="text-subtitle-1">
                    Dialogue positioned at bottom 0 and left 0.</p>
                </v-col>
              </v-row>
            </v-card-text>

          </v-container>
        </v-card>
      </v-modal>
    </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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am struggling with how to print the value of an object in nativescript-vue. Can anyone help me with

Upon examining the nativescript-vue code provided, I encountered an issue where I am unable to print json.city.value in the Label element. However, I can successfully print it within the script section; specifically inside the readFromJson method using c ...

Position the logo at the center of the Vuetify navigation bar

In my Vue/Vuetify application, the navigation bar consists of several elements: A hamburger menu An SVG logo that is linked to the homepage Various navigation links I am trying to style the elements as follows: left-align the menu, center the logo, and r ...

What is the method for customizing the background color in a .vue file using Bootstrap?

Can anyone assist me in updating the background color of a div class from grey to white? The code is within a .vue file using Bootstrap and includes an enclosed SVG file. Here's the snippet: <div class="text-left my-3 bg-white"> <button var ...

I need to position a Vue component at the top of the page for a specific view only

How can I ensure that the component SiteHead only appears at the very top of the HomeView page, above the SiteNavigation component? If I place the SiteHead component within the HomeView.vue code, it ends up below SiteNavigation. Here is my App.vue code: & ...

Angular 8 allows for the creation of custom checkboxes with unique content contained within the checkbox itself, enabling multiple selection

I'm in need of a custom checkbox with content inside that allows for multiple selections, similar to the example below: https://i.sstatic.net/CbNXv.png <div class="row"> <div class="form-group"> <input type ...

Using Javascript to map an array with objects from a different array and then returning the computed array

I'm struggling to solve a seemingly simple issue. I have an array that looks like this: Array 1: [ { "id": 1, "date": "2019-03-27", "time": 1, "max_tasks": 3, "reservations": [ 5, 2 ...

Semantic UI dropdown field not displaying selected option text

I've encountered an issue while working with React Semantic UI. I'm trying to render a dropdown and have configured it so that the selected option's text should display in the field. However, when I choose an option from the dropdown, instea ...

Looking for a way to connect a background image in Vue CLI?

When running the code below, I encounter an issue. The code runs properly but the images are not displaying and instead showing the URL as unknown. How can I fix this problem? The images definitely exist. <template> <div class="slider">< ...

Partial button clickability issue

There is a puzzling error where the button in the 'red area' is not clickable, and I can't seem to figure out why. Below are images illustrating the issue: https://i.stack.imgur.com/aPfcR.png https://i.stack.imgur.com/v5knZ.png Upon reac ...

Inject arguments/data into the methods to showcase the name within a newly instantiated component in VueJS

I implemented a feature that allows collapsing sections within a table body. There is an "add" button represented by the "+" sign, and when clicked, it adds a new collapse section with content. I want to display the name of the data row (e.g., "iPhone") wh ...

The image is not resizing correctly

Currently, the background-image on my website displays properly when the browser occupies the entire screen. However, when I resize the browser window, the image shrinks to a certain point and then suddenly stops adjusting. Here is a visual representation ...

Using Vue with Firebase to fetch a specific range of data starting from a particular record and ending at the

I am looking to retrieve all records from a certain record to the very last one in my database. ref.orderByChild("date").equalTo("19/11/2020 @ 19:50:29").on("child_added", (snapshot) => { console.log(snapshot.va ...

How can I restrict a plugin to just one component in Nuxt.js?

I'm working on a blog website using nuxt.js and I need to import an editor in only one component without using the nuxt.config.js file. I've tried the following approach, but it doesn't seem to be working. //Inside '~/plugins/vue2-ed ...

Tips for creating stylish diagonal backgrounds using Bootstrap 5

Is there a way to achieve diagonal styled backgrounds, like the examples shown below, while using Bootstrap 5 and (s)css? It would be ideal if this could be seamlessly integrated with other Bootstrap background utilities as outlined in the documentation h ...

How to apply CSS classes to dynamically injected HTML in Angular 7

One of the challenges I'm currently facing is how to assign a CSS class based on a calculation in my component. Here's a snippet from my component class: @Component({ selector: 'app-render-json', template: `<div [innerHtml ...

Adding color to the header's top section and leaving the navigation bar untouched

A few days ago, I posted a question on this platform regarding customizing CSS related to search forms within Bootstrap. The response I received from Charlie was incredibly helpful in refining the code for my header and navigation elements. You can view hi ...

CSS gradient covering 50% horizontally from left to right with a vertical transition from top to bottom causing issues on mobile

For a project, I needed a 2-column layout with the left column being red and the right column white. The left column contained text while the right column had an image. It looked great on larger screens, but I encountered issues on smaller screens due to t ...

Trouble with CSS3 Menu Layout and Gradient Display Issues

My task is to replicate this menu: I'm having trouble creating the gradient. Completed Why can't I see it in my code? http://jsfiddle.net/Vtr6d/ Here's what I currently have: CSS: .mainOptions{ float:left; margin:0 20px 0 20px; ...

Manipulate the css pseudo-element :after using jQuery's .siblings() method

How can I use jQuery to edit the :after element created by CSS? <div class="box"> <h3 class="social">Social</h3> <ul> <li><a href="https://www.youtube.com/" onmou ...

Change justify-content-between to something else

After successfully fixing the issue with aligning the navbar brand in the middle of my navigation bar, I am now facing a new challenge. I want to add a button right before the right navigation toggle, but all my attempts have been unsuccessful so far. I&ap ...