K
K
Konstantin Malyarov2017-08-21 23:06:26
Node.js
Konstantin Malyarov, 2017-08-21 23:06:26

How to automatically send information when opening a page?

I have a page that has a form:

<form v-on:submit="send">
                        <div class="message" v-for="message in messages">
                            @{{ message }}
                        </div>
                        <input id="message"/>
                        <button>Отправить</button>
                    </form>

There is a script that works on the button :
var socket = io('http://cniishub.ru:8080/');

new Vue({
    el: '#app',
    data: {
        messages: [],
        message: 'HW',
    },
    ready: function () {
        socket.on('eventClient', function (data) {
            this.messages.push(data);
        }.bind(this));
    },
    methods: {
        send: function (e) {
            e.preventDefault();
            socket.emit('eventServer', location.pathname);
            this.message = null;
        }
    }
})

How to make it so that when the page is loaded, a string is automatically sent, and not by a button?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-08-21
@BorisKorobkov

socket.on('connect')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question