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

How can I differentiate between an unreachable server and a user navigating away in a $.ajax callback function?

Situation: You have a situation where several $.ajax requests to the server are still in progress. All of them end with xhr.status === 0 and xhr.readyState === 0. Possible reasons for this issue: The server might be down (EDIT: meaning it is unreachabl ...

Discovering the generic type from an optional parameter within a constructor

Looking to implement an optional parameter within a constructor, where the type is automatically determined based on the property's type. However, when no argument is provided, TypeScript defaults to the type "unknown" rather than inferring it as "und ...

A beginner's guide to integrating three.js into your React projects

I am having trouble integrating three.js into my React application. Despite following the basic sample from the three.js documentation, I am unable to load it on the canvas. Initially, I successfully implemented the sample in a vanilla.js sandbox. However ...

Are you harnessing the power of Ant Design's carousel next and previous pane methods with Typescript?

Currently, I have integrated Ant Design into my application as the design framework. One of the components it offers is the Carousel, which provides two methods for switching panes within the carousel. If you are interested in utilizing this feature using ...

Which is the Better Choice for an MMO WebSocket Server: Node.js or C++?

Contemplating creating a live game using WebSockets for the web has been on my mind. With my knowledge of Node.js, it's tempting to develop it there. However, C++ appears to be the favored server language due to its speed. Would it be best to try bui ...

"Centered in the middle of the screen, an animated

Encountering an issue with this code on Chrome. Clicking on the checkbox causes the text/checkbox to shift in position/padding/margin unexpectedly.. :( View the code on JSFiddle HTML <input id="inp" type="checkbox" /> <div id="cb" class="inp_ch ...

Retrieve the route from a specific node in the jstree structure

Looking to retrieve the paths of selected nodes in jstree? You'll need the complete path of the nodes. I have a php file that generates the JSON, structured like this: header("Content-Type: application/json; charset=utf8"); echo json_encode(dir_to_ ...

The cycle of Vue.js is malfunctioning

What could be the reason why this code is not iterating 10 times to build a model of 10 equal divs? https://jsfiddle.net/chrisvfritz/50wL7mdz/ <script src="https://unpkg.com/vue"></script> <div v-for="n in 10" id="example"> ...

Tips on connecting the endpoints of two parallel quadratic Bezier curves that both begin with a MoveTo command

I am currently working on creating a Sankey Diagram from scratch using VueJS and SVG. I have encountered challenges in closing the paths of two parallel quadratic Bezier curve paths from nodes to nodes. For instance, after some additional calculations, I ...

What is the proper way to implement parameters and dependency injection within a service?

My objective is to achieve the following: (function(){angular.module('app').factory("loadDataForStep",ls); ls.$inject = ['$scope','stepIndex'] function ls ($scope, stepIndex) { if ($routeParams ...

Display the div according to the $index selected from the AngularJS list

Below is the structure of my HTML code: <div class="col-md-4"> <ul class="list-group text-left"> <a href="#" class="list-group-item" ng-click="showData($index)" ng-repeat="field in Data"> {{ field.name }}</a> ...

What is the correct way to implement Vue.use() with TypeScript?

I am trying to incorporate the Vuetify plugin into my TypeScript project. The documentation (available at this link) suggests using Vue.use(), but in TypeScript, I encounter the following error: "error TS2345: Argument of type '{}' is not assign ...

Utilizing Jquery's each() method to retrieve the exact position of a specific class element

Is there a way to determine the position of the "owl-item active" element? The current position is 2 out of 3 total photos. <div style="transform: translate3d(-825px, 0px, 0px); transition: all 0.25s ease 0s; width: 48675px;" class="owl-stage"> ...

Dropzone.js: Creating a personalized file explorer to include files that have already been uploaded

Don't worry, this isn't your typical "can't load files from the server" query... I'm looking to allow users to view files on the server in a bootstrap modal and then select specific files. After selection, I want to close the modal and ...

Generate a fresh object with distinct identifiers

I am interested in creating a new object, utilizing unique keys consisting of comma-separated IDs. For instance, I have: const d = { "1,2,3,4,5,6,7,8,9,10": [ "created_by", "modified_on", "external_o ...

Looking to utilize Axios in React to make API calls based on different categories upon clicking - how can I achieve this?

My current issue involves making an API call upon clicking, but all I see in my console is null. My goal is to have different API categories called depending on which item is clicked. const [category, setCategory] = useState(""); useEffect(() => { ...

What are the advantages of utilizing NGRX over constructor-injected services?

Have you ever wondered about the benefits of using NGRX or NGXS for an Angular application instead of constructor injected services to manage component IO? Is it simply to prevent mutation of component properties references without replacing the entire pr ...

What is the best way to include message body in CDATA using strophe?

I have a task to create messages in a specific format by using the following code: $msg({to: 'user', from: 'me', type: 'chat'}).c("body").t('some data'); This code generates the message structure as follows: <m ...

What are the steps for implementing Babel in a CLI program?

Currently, I am working on developing a CLI program in Node using Babel. While researching, I came across a question on Stack Overflow where user loganfsmyth recommended: Ideally you'd precompile before distributing your package. Following this ad ...

Using an external function to implement Javascript and AJAX interactions

function makeAjaxRequest(destination_full_url) { if (window.XMLHttpRequest) {// code for modern browsers xmlhttp = new XMLHttpRequest(); } else {// code for old Internet Explorer versions xmlhttp = new ActiveXObject("Microsoft.XMLH ...