K
K
Konstantin Malyarov2018-03-12 01:43:31
Vue.js
Konstantin Malyarov, 2018-03-12 01:43:31

How to get the value of a VueJS variable?

JS

var socket = new WebSocket("ws://" + window.location.host + ":8081/")

new Vue({
    delimiters: ['{>', '<}'],
    el: '#patient_history',
    data: {
        department: ''
    },
    methods: {
        getWebSocket: function () {
            var self = this
            socket.onopen = function () {
                console.log("Соединение установлено.");
                console.log(self.department)
                socket.send(document.location)
            };

            socket.onclose = function (event) {
                if (event.wasClean) {
                    alert('Соединение закрыто чисто');
                } else {
                    alert('Обрыв соединения'); // например, "убит" процесс сервера
                }
                alert('Код: ' + event.code + ' причина: ' + event.reason);
            };

            socket.onmessage = function (event) {
                console.log(event.data)
            };

            socket.onerror = function (error) {
                alert("Ошибка " + error.message);
            };
        },
    },
    created: function () {
        console.log(this.department)
        this.getWebSocket()
    }
})

HTML
<b>Отделение:</b> {{ current_history.department }} <span v-model="department">{{ current_history.department.id }}</span>

The console is empty. How to get value after page load?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2018-03-12
@LiguidCool

This is how you call console.log(this.department) before getting any data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question