I am struggling to create a modal component for a settings button

I am currently working with Quasar VueJS and I have a requirement to add a button on my navbar that will trigger a pop-up dialog settings panel. This settings panel will be used for various functionalities such as dynamic theming, although that is somewhat off-topic.

However, I am facing significant challenges in trying to implement this feature.

"layouts/MainLayout.vue"

<template>
        <q-btn
          unelevated
          icon="settings"
          label="Settings"
          color="primary"
          v-on:click="SetterUpper"
        />
</template>

<script>
import SetterUpper from "components/SetterUpper";

export default {
  name: "MainLayout",
  Component: {
    SetterUpper
  },
};
</script>

"components/SetterUpper.vue"

<template>
  <q-dialog v-model="SetterUpper" persistent>
    <q-card>
      <q-card-section class="row items-center">
        <q-avatar icon="settings" color="primary" text-color="white" />
        <span class="q-ml-sm">Placeholder</span>
      </q-card-section>

      <q-card-actions align="right">
        <q-btn flat label="Cancel" color="primary" v-close-popup />
        <q-btn flat label="Save" color="primary" v-close-popup />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
export default {
  name: "SetterUpper",
};
</script>

Answer №1

If you want to simplify the communication between components regarding the state of a variable, consider moving your q-dialog to the parent component. By doing this, you eliminate the need to pass props or emit events.

Here is an example:

<template>
  <q-layout view="lHh Lpr lFf">
    <q-dialog v-model="dialogEnabled" persistent>
      <SetterUpper />
    </q-dialog>
    <q-btn
      unelevated
      icon="settings"
      label="Settings"
      color="primary"
      v-on:click="dialogEnabled = true"
    />
  </q-layout>
</template>

<script>
import SetterUpper from 'components/SetterUpper'
export default {
  name: 'MainLayout',
  components: {
    SetterUpper
  },
  data() {
    return {
      dialogEnabled: false
    }
  }
}
</script>

SetterUpper.vue

<template>
  <q-card>
    <q-card-section class="row items-center">
      <q-avatar icon="settings" color="primary" text-color="white"/>
      <span class="q-ml-sm">Placeholder</span>
    </q-card-section>

    <q-card-actions align="right">
      <q-btn flat label="Cancel" color="primary" v-close-popup/>
      <q-btn flat label="Save" color="primary" v-close-popup/>
    </q-card-actions>
  </q-card>
</template>

<script>
export default {
  name: 'SetterUpper'
}
</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

What is the process for sending a message from the internet to a mobile device?

We are currently in the process of developing a website that sends SMS alerts to users for specific services, however I am struggling to set up a script that can perform this function. If anyone has any suggestions or recommendations for a solution, pleas ...

What is the best way to design a new class that will serve as the parent class for both of my existing classes, allowing them

I am facing a challenge with my programming classes. I have two classes, "Player" and "Enemy", each with similar methods and properties. I want them to inherit from a parent class that I'll create called "Game Object". How can I approach creating thi ...

Is the removal of the Vue-Router link happening when you click on the top app bar icon in Google Material

Review of the following code snippet: <!DOCTYPE html> <html> <head> <title>test</title> <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='vie ...

Create a single line of content for a carousel display

Seeking a solution where I can have a container that slides sideways without stacking in rows, I have exhaustively searched for answers using different keywords like single row, inline, flexbox, and grid but to no avail. Any assistance will be highly appre ...

Comparing jQuery AJAX with UpdatePanel

Our team is facing the challenge of dealing with a page containing an overwhelming amount of jQuery code (specifically around 2000 lines) that has become difficult to maintain. We are considering shifting some of this functionality to the server side for ...

Vuejs v-model input value does not refresh dynamic data updates

I am currently working on incorporating the "pokemonName" parameter into the API URL that is being accessed through axios. The aim is to showcase the JSON data for each newly entered Pokémon by the user in a text input field. Below is my HTML code: &l ...

Where can Vue.js be found?

After dedicating an hour to watching instructional YouTube videos on Vue.js, I am still struggling to grasp the language! In the past, I have worked with Node.js, Jquery, and Mongodb to develop websites... I believe that web applications require multiple ...

The code is running just fine when tested locally, but it seems to encounter an issue when accessed remotely, yielding

Currently, I am in the process of developing a dual twin setup using a Raspberry Pi. The goal is to simulate a continuous transmission of body temperature data, which is then sent to a server that stores the information in a MongoDB database. Everything fu ...

Achieve horizontal wrapping of div elements

Currently, I am developing a blog where search results for articles will be displayed within divs. The design of the website is completely horizontal, meaning that articles scroll horizontally. Creating a single line of divs is straightforward, but it&apo ...

The Vue composition api fails to update the text field's bound value

I've encountered an issue while trying to update an attribute of an object after initialization. Here's a simplified version of my component: <template lang="pug"> div v-text-field(v-model="object.name") v-text-field(v-model="ob ...

Updating the value of a v-text-field in Vuetify

What is the best way to modify input values? Here is an example: `https://jsfiddle.net/mbqjp4ax/` If a number entered is greater than 5, the system should automatically input the number 9 instead. While this works correctly when entering numbers greater ...

Merge the capabilities of server-side exporting and client-side exporting within Highcharts for Vue

While working with Highcharts' export server to download charts as images, I encountered a challenge. I needed to implement the client-side (offline) exporting feature in a single chart due to the large number of data points. However, after enabling c ...

What are the reasons behind the absence of CORS issue on the backend server?

I have been working on a fun project using Vue and ran into a CORS issue when making api requests with axios from the front end. Can anyone provide some insight? Access to XMLHttpRequest at '...' from origin 'http://localhost:8080' ...

JavaScript - issue with event relatedTarget not functioning properly when using onClick

I encountered an issue while using event.relatedTarget for onClick events, as it gives an error, but surprisingly works fine for onMouseout. Below is the code snippet causing the problem: <html> <head> <style type="text/css"> ...

Arrange Data Alphabetically using a JavaScript Loop

I have a unique program that extracts data from 2 different URLs. Using CSS, I automatically generate a sleek Business Card design in a 'for' loop. Now, I'm faced with the challenge of creating a Sort Alphabetical button based on "${users[co ...

Using Vue to dynamically upload multiple files simultaneously

Although this question has been asked frequently, most of the answers do not address a key issue - how to upload multiple images while knowing which image belongs to which data. Attempting to bind v-model to input file doesn't work as expected, and ev ...

Trying to utilize RegEx for my project, but feeling stuck on how to solve my problem

^\d{1,12}$|(?=^.{1,15}$)^\d+\.\d{1,2}$ This is the current regular expression I am using. I need to adjust the maximum limit to 100,000,000,000 with an option for two decimal places. Additionally, I would like users to be able to inpu ...

What is the best way to maintain a Tampermonkey script within Selenium?

I'm trying to execute a JavaScript script before the page loads, so I've placed it in Tampermonkey. However, the script doesn't persist after closing the driver. Whenever I run the code again, the saved script is no longer there. This code u ...

Retrieval of components from JSON array of objects

I have a JSON array containing objects stored on the server. How can I access the first object to print its contents? The data is in the following format: [ { "eventId": "8577", "datasetId": "34", "nodeId": "8076", "typeId": "4", "type": ...

Ways to extract data from a JSON object

When using my web application, the Web API responds with the following JSON object: [ { "templateID":1, "template":"{\r\n \"Body\": \"sample date hete hee. Name\"\r\n}" }, { "templateI ...