R
R
Rishat Sultanov2018-04-18 10:34:55
Socket.io
Rishat Sultanov, 2018-04-18 10:34:55

How to include a package when the component is mounted?

Hello ^)
How to enable vue-socket.io connection when user has mounted component, not always when user loads app.js?

<template>

</template>
    
<script>

    import VueSocketio from 'vue-socket.io';
    Vue.use(VueSocketio, 'http://laravel-chat.test:6001');

    export default {
        mounted() {
            var vm = new Vue({
                sockets:{
                    connect: function(){
                        this.$vs.notify({title:'Соединение',text:'Вы успешно подключились к чату!',color:'success',position:'bottom-center'});
                    },
                    connect_error: function(){
                        this.$vs.notify({title:'Соединение',text:'Ошибка сервера, не могу подключить к чату!',color:'danger',position:'bottom-center'});
                    }
                }
            });
        }
    }
</script>

<style scoped>

</style>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question