Modify the size value dialog during runtime

I am attempting to create a property or method that can change the size of my container dialog built using Vuetify.

Initially, I need it to look like this:

<v-flex xs12 md10>

I believe that by creating a variable property, I can dynamically change this value in another part of my website. For this purpose, I am trying the following:

<v-flex xs12 v-model="tamanio_dialog">

And I have added a prop in my component:

props: {
        formula:            { type: Object, required: true },
        loading:            { type: Boolean, default: false },
        tipoLiquidacion:    { type: Object, required: true },
        tipoLiquidacion_id: { type: Number },
        agrupacion_id:      { type: Number },
        aliasAplicacion:    { type: String, required: false},
        // INHERITS DATA FROM AUTHENTICATED USER
        usuario: {
            type: Object
        },
        tamanio_dialog: ['md10']
    },

When I call my Dialog, I am passing this property:

:tamanio_dialog="md12"

Although the size of my container dialog appears to be correct, the console log returns:

Property or method "md12" is not defined on the instance but referenced during render.

UPDATE

In my parent component, the size is always set to xs12 when it should be md10 in desktop size but xs12 only in my dialog.

I have tried the following variations in the child component:

tamanio_dialog="md12"
tamanio_dialog="'md12'"
:tamanio_dialog="'md12'"

I have updated the props component as follows:

props: {
            formula:            { type: Object, required: true },
            loading:            { type: Boolean, default: false },
            tipoLiquidacion:    { type: Object, required: true },
            tipoLiquidacion_id: { type: Number },
            agrupacion_id:      { type: Number },
            aliasAplicacion:    { type: String, required: false},
            // INHERITS DATA FROM AUTHENTICATED USER
            usuario: {
                type: Object
            },
            tamanio_dialog: {
                type:String, 
                default:'md10'
            }
            
        },

Update 2

I have attempted the following in my component where I expect the desired size:

<v-flex xs12 :mdProp="mdProp">

The props in this component are:

mdProp: {
    type: Number,
    default: 10
 }

When I call this component in the dialog:

:mdProp="12"

The result always sets the size to 12 and mdprop:

flex xs12 mdProp

Update 3

PaginaFormulasForm.vue (my child component)

mdProp: {
                type: Number,
                default: 10
            }

<v-flex :md="mdProp">

PaginaTipo page where I am building the dialog:

<v-card-text>
                                <PaginaFormulasForm :formula="formulaNuevoProps.formula"
                                        :loading="formulaNuevoProps.loading"
                                        :tipoLiquidacion="tipoLiquidacionById"
                                        :tipoLiquidacion_id="formulaNuevoProps.tipoLiquidacion_id"
                                        :agrupacion_id="formulaNuevoProps.agrupacion_id"
                                        :aliasAplicacion="'nuevoLinea'"
                                        :usuario="usuario"
                                        :mdProp="12"
                                        @guardar="crearFormulaEnLineaLiquidacion"
                                        @cerrar="cerrarDialogoFormula()"
                                        @toggleNuevoFormula="toggleNuevoFormula"
                                    />
                            </v-card-text>

The result in the web browser always shows md12 as the class:

class="flex md"

What am I doing wrong? Thank you for reading and sorry for any language errors.

Answer №1

When using

v-model="tamanio_dialog"
and setting the value of tamanio_dialog to md12, it may mistakenly interpret it as v-model="md12". This happens because md12 is considered a variable that is not existing in your data, resulting in an error.

To avoid this issue, consider utilizing grid classes such as xs="12", md="10", or md="12". Try the following approach-

-child component:

<child-component />
<child-component :md_prop="8" />
<child-component :md_prop="12" />

-parent component:

Note: v-flex is only available in Vuetify 1.x, whereas you are using Vuetify 2. Therefore, utilize v-col instead.

<v-col xs="12" :md="md_prop" />
props: {
  md_prop: {
    type: Number,
    default: 10
  }
} 

Check out the demo where columns are dynamically created based on the passed props.
(For better visualization, view the result in full_page mode as the md class takes effect only on the full page.)

Vue.component('child-component', {
  template: `<v-row no-gutters class="mt-2"><v-col :md="md_prop" class="red lighten-4">md size - {{ md_prop }}</v-col><v-col class="amber lighten-4">Hello World</v-col></v-row>`,
  props: {
    md_prop: {
      default: 10,
    },
  }
})

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
})
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0472716144362a7c">[email protected]</a>/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee989b8b9a878897aedcc096">[email protected]</a>/dist/vuetify.js"></script>
</script>
<head>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4a2a1b1a0bdb2ad94e6faac">[email protected]</a>/dist/vuetify.min.css" rel="stylesheet">
</head>
<div id="app">
  <v-app id="inspire">
    <v-card>
      <child-component/>
    </v-card>
    <v-card>
      <child-component :md_prop="12"/>
    </v-card>
    <v-card>
      <child-component :md_prop="8"/>
    </v-card>
  </v-app>
</div>

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

Creating a series of spots arranged in a semi-transparent line using JavaScript for a unique canvas

My attempt at creating a highlighter is encountering issues with transparency The problem might be due to using lineCap=round, resulting in multiple dark spots appearing in a single line (which shouldn't happen). It's difficult to fully describe ...

What is the best way to create a clickable <li> element from AJAX search results that display dynamic HTML?

Utilizing AJAX technology, I have implemented a live search feature that populates results from a database as the user types in a text field. The results are presented in an unordered list format. My goal is to allow users to click on an item within the li ...

Can you please provide the appropriate PropTypes for a dictionary in a ReactJS project?

Looking for something along the lines of y = {"key0": [value0, value1], "key1":[value2]} What is the proper way to define the proptypes for y? ...

"Running 'npm run build' in Vuejs seems to have a mind of its own, acting

Recently, I completed a project and uploaded it to Github. The issue arises when I attempt to clone it to my live server - only about 1 out of 10 times does everything function correctly after running npm run build. My setup consists of Ubuntu 16 with ngin ...

Is it possible that the rows variable is not updating correctly due to an issue with the setState function, resulting in the changes not being displayed in

This code serves a similar purpose to a ToDo List feature. The add button is intended to add an array object to the list of rows, which are displayed in the UI as TextFields through iteration with rows.map. The subtract button should remove the selected ro ...

The filter functionality is not functioning properly in AngularJS

Currently, I am working on an AngularJS extension and encountering an issue with the filter functionality. In the popup page of my extension, there is a button. Upon clicking this button, the ancestor node of the button gets blocked, and its relevant info ...

Retrieve Javascript files from the local static directory

Currently, I am developing a small project with Nuxt JS and I am facing a challenge in calling some Javascript files from my static directory. When it comes to CSS files, I have been able to do it successfully using the following code: css: [ './stat ...

Guide on how to beautify HTML and generate output files in the identical directory as the current one

Hey there! I'm currently working as a junior front-end developer and have recently delved into using gulp. One of the challenges I face is dealing with HTML files received from senior developers that aren't well-formatted, containing excessive wh ...

Is there a particular motive behind the decision for `arguments` to be treated as an object

Today while coding, I came across something puzzling. arguments.concat(someNumber); This line gave me an error for undefined function. Initially, I assumed that arguments was a native object for optimization purposes, but later discovered it's simp ...

Guide on creating a conditional column in a kendo UI grid with the use of AngularJS

Is there a way to dynamically add a column to the Kendo UI grid based on JSON data? Consider the following JSON input: [{ "ProductID": 1, "ProductName": "Chai", "Supplier": { "SupplierID": 1, "SupplierName": "Exotic Liquid ...

"Changing a Java script base addon file to a customized addon in Odoo 16: A step-by-step guide

Here is the JavaScript file located in the "documents" enterprise base addon: I want to include the field "document_type_id" in the export const inspectorFields = [] array through a custom addon. /** @odoo-module **/ import { device } from "web.confi ...

What steps do I need to take to execute a script that utilizes the mootools library within an asp.net environment

I've been working on a website that includes a mail form. I'm using the Mootools 1.4.3 library along with FormCheck 1.6.js. However, when I click the button, nothing happens except for the page refreshing. I really like this form and want to make ...

Is it really necessary to import React from 'react' in the index.js file when importing react is no longer required?

Currently diving into the world of React.js. I recently found out that after version 17, importing React is no longer necessary. My current React version is v18.2.0. Here's the code snippet in question: // import React from 'react'; import ...

Ensuring consistency of variables across multiple tabs using Vue.js

In my vuejs front-end, a menu is displayed only if the user is logged in. When I log out, the variable isLogged is updated to false, causing the menu to hide. If I have multiple tabs open with the frontend (all already logged in) and I logout from one tab ...

Vue.js routing and mixin dilemma

Calling all Vue developers! I am currently working on a vuebnb tutorial and running into an issue with routing and mixins. I have attempted to assign data before entering the router using the beforeRouteEnter guard, but it seems like my template is being r ...

Investigating the variety of HTTP 206 responses pertaining to video content

Currently, I am utilizing Amazon CloudFront to serve HTML5 videos. These videos are being requested through HTTP range requests and the expected responses are often in the form of HTTP 206 Partial Content. I have a requirement where I want to log the requ ...

Utilize the #value template in PrimeVue Dropdown to retrieve country code for setting the default selected flag

In the student edit modal, I have a Dropdown where I need to display a flag for the default country. When using PrimeVue, I can access the country code from a template using #option="slotProps", but not with #value="slotProps". This m ...

Transforming a value within a controller into a directive

I am uncertain if I am approaching this correctly, but my goal is to convert a piece of code from a controller to a directive. The reason for this change is that I want to reuse the code with different values without creating multiple large object literals ...

Firebase Error: In order to deploy without hosting via source, options must be provided. (app/no-options)

After developing a Next.js application, I integrated Firebase authentication and utilized the useContext hook for managing user state throughout the app. Here's the snippet of code for the AuthContext: auth.js import { createContext, useState, useEff ...

Fetch information from the input field and send it to the Redux state

Looking for a solution - I'm working on a simple todo app where I need to store user input value in the redux state. The input value is currently stored in local state until the user clicks the "add" button. The main issue : How can I pass this input ...