Information sent to a slot does not trigger a response

Trying to create a mobile-friendly chat app, I want to hide the new message button during conversations and use a different button on desktop. In addition, I have a dialog for creating new chat groups.

<v-dialog transition="dialog-top-transition" max-width="600">
                <template v-slot:activator="{ on, attrs }" v-if="!showMessageList">
                    <v-btn fab dark color="primary" fixed right bottom v-bind="attrs" v-on="on" class="d-flex d-sm-none">
                        <v-icon dark>mdi-message-outline</v-icon>
                    </v-btn>
                </template>
                <template v-slot:default="dialog">
                    <v-card min-height="70vh">
                        <v-toolbar color="primary" dark>New Message
                            <v-spacer></v-spacer>
                            <v-btn icon @click="dialog.value = false">
                                <v-icon>mdi-close</v-icon>
                            </v-btn>
                        </v-toolbar>
                        <v-card-text>
                            <v-text-field label="Find contact" hide-details="auto" v-model="contactQuery" @keydown="searchContact"></v-text-field>
                            <contacts :contacts="contacts" :user="user" v-on:new-group="addGroup"></contacts>
                        </v-card-text>

                    </v-card>
                </template>
            </v-dialog>

app.js

const app = new Vue({
    el: '#app',
    vuetify: vuetify,
    data: {
        //
        user: {},
        contactQuery: "",
        contacts: [],
        showMessageList: true,
    },
    created() {
        this.showMessageList = !this.isMobile();
    }
    methods: {
        isMobile() {
            return window.innerWidth < 500;
        },
        openMessages() {
            this.showMessageList = true;
        },
        hideMessages() {
            if (this.isMobile()) {
                this.showMessageList = false;
            }
        },
        showGroups() {
            if (this.isMobile()) {
                return !this.showMessageList;
            }
            return true;
        }
    }

template

<chat-groups :user="user" :groups="groups" :curr-group="group" :is-mobile="isMobile" v-on:group-change="changeCurrGroup" v-on:open-messages="openMessages"></chat-groups>

ChatGroups.vue

export default {
    props: ["groups", "currGroup", "user", "isMobile"],
    data() {
        return {
            selectedGroup: this.currGroup
        }
    },
    methods {
//...
        openMessages() {
            if (this.isMobile()) {
                this.$emit("open-messages");
            }
        },

The challenge lies in making showMessageList reactive so it consistently hides the button. Additionally, how can the dialog be hidden from another location, such as a button in a separate container?

Answer №1

To add an event listener to the window, follow these steps:

new Vue({
  el: "#app",
  data() { return { windowWidth: window.innerWidth } },
  mounted() {
    window.addEventListener('resize', () => {
      this.windowWidth = window.innerWidth
      console.log(this.isMobile)
    })
  },
  computed: {
    isMobile() {
      return this.windowWidth <= 768
    }
  }
})

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

Utilizing X-editable and Parsley to trigger dual Ajax calls

Here is a snippet of code I am working with: $.fn.editable.defaults.mode = 'inline'; var editable = $('.x-editable').editable({ send: 'always', validate: function() { var form = editable.next().find('form ...

The componenetDidUpdate() method is failing to trigger

I am currently attempting to remove a <Table> data entry. My process involves selecting a single row within the <Table> and clicking on a custom-made Delete button, which triggers the delete function. While the data is successfully deleted on ...

Struggling with handling numbers and special symbols in the Letter Changes problem on Coderbyte

Hello I have been struggling to find a solution for my current issue. The problem lies within an exercise that requires changing only alphabetical characters, but test cases also include numbers and special characters which are being altered unintentionall ...

What steps can I take to prevent the user from clicking on a different edit button for another row?

Is there a way to prevent users from clicking the edit button in another row before they have saved their changes? I want users to click the save button before editing another row. How can I reset the textbox to its original form or remove it altogether ...

Is it possible for a local variable in Vuex to update with a mapState value, so that changing the local variable will also update

Why is my Vuex object being modified when I assign its value to a local variable and make changes to the local copy? Should I provide my store.js for reference? My code looks like this: data() { return { localObject: [], }; }, computed: ...

"Implementing a full page refresh when interacting with a map using

Here is an example of how I display a map on the entire page: <div id="map_canvas"> </div> UPDATE 2: I have successfully displayed a menu on the map, but there is a problem. When I click on the button, the menu appears briefly and then disapp ...

Is there a way to manipulate a DOM element using a component?

import { FlagIcon, ChartIcon, ShareIcon, ConnectIcon, HearIcon, AnalyticsIcon, AddIcon, RemoveIcon, } from "../../icons/Icons"; import "./Sidebar.scss"; import ReactDOM from "react-dom"; const Sidebar = () =&g ...

Generate TypeScript type definitions for environment variables in my configuration file using code

Imagine I have a configuration file named .env.local: SOME_VAR="this is very secret" SOME_OTHER_VAR="this is not so secret, but needs to be different during tests" Is there a way to create a TypeScript type based on the keys in this fi ...

Creating an error handler in PHP for dynamically adding or removing input fields is a crucial step in ensuring smooth and

I designed a form with multiple fields, including a basic input text field and dynamic add/remove input fields. I successfully set the first field as required using PHP arguments, but I'm struggling to do the same for the additional fields. I need as ...

Issues with displaying images in Fancybox

I've integrated FancyBox into my website, but I'm experiencing a minor issue. While the FancyBox works perfectly in Dreamweaver, it seems to malfunction in various browsers. As someone who is not well-versed in programming, I'm struggling t ...

Unable to locate the accurate information

Every time I run the cycle, there should be a match with the specified parameters and the message "OK" should appear. However, I am always getting a result of "No". request( { url: 'http://localhost:5000/positions/get', metho ...

Guide on verifying the presence of a value in a textbox using vue

I'm currently working on a form that requires only numbers and text input. Any characters like ., ,, or spaces are not allowed in the textbox. Here are some of the attempts I've made, but unfortunately, they did not yield the desired results: i ...

What is the Typescript definition of a module that acts as a function and includes namespaces?

I'm currently working on creating a *.d.ts file for the react-grid-layout library. The library's index.js file reveals that it exports a function - ReactGridLayout, which is a subclass of React.Component: // react-grid-layout/index.js module.exp ...

Aborting HTTP POST requests in IE due to error code 0x2ee2

Currently, I am utilizing angularjs for file uploads to my API. The page features a multi-file select option where users can choose one or multiple files. Upon selection, the page initiates calls to the api and uploads each file individually using requests ...

An alternative to PHP's exec function in Node.js

I am interested in developing a piece of software using C (such as prime number factorization) and hosting it on my web server with Node.js. Following that, I would like to create an HTML document containing a form and a button. Upon clicking the button, ...

What's the best method for uploading a file to AWS S3: POST or PUT requests?

Could you please provide insights on the advantages and disadvantages of utilizing POST versus PUT requests for uploading a file to Amazon Web Services S3? Although I have come across some relevant discussions on platforms like StackOverflow, such as this ...

Create a feature that allows users to search as they navigate the map using Leaflet

Exploring the idea of incorporating a dynamic "Search as I move the map" feature similar to Airbnb using Leaflet. Striving to strike a balance between loading data relevant to the displayed portion of the map and minimizing unnecessary API requests trigger ...

Displaying country-specific API details (such as capital and currency) in a card container when selecting a country from a dropdown menu

My objective is to display the card information for South Africa as the default value, even before entering any country's name into the search bar input field or selecting a specific country from the provided list. I am utilizing the restcountries API ...

React unit tests experiencing issues with MSW integration

After creating a basic React application, I decided to configure MSW based on the instructions provided in order to set it up for unit tests in both node environment and browser. The main component of the app utilizes a custom hook called useFormSubmission ...

Struggling with testing the checkbox when it changes inside the CardHeader Avatar={} component

I've recently implemented a feature similar to the example showcased on MaterialUI's TransferList. However, I'm encountering difficulties accessing a checkbox within the avatar={}. The project utilizes Jest and Enzyme for testing purposes. T ...