A
A
arseniylebedev2020-02-09 21:16:58
Vue.js
arseniylebedev, 2020-02-09 21:16:58

v-on:change not working on select element?

<template>
    <div class="vpn-path-configure">
        <form>
            <div class="form-group" v-for="(path, index) in pathElements" :key="'server-' + index">
                <label :for="'server-' + index" :key="'label-' + index">Сервер #{{ index + 1 }}</label>
                <select class="form-control" :id="'server-' + index" v-on:change="changeServer(index, $event)" :key="'select-' + index">
                    <option v-for="(server, server_index) in path.servers" :key="'option-' + index + '-' + server_index" :value="server_index">{{ server.ip + ':' + server.port }}</option>
                </select>
            </div>
            <button class="btn btn-primary">Создать</button>
        </form>
    </div>
</template>

<script>
    export default {
        name: "vpn-path-configure",

        props: [
            'serversProp',
        ],

        data() {
            const servers = JSON.parse(atob(this.serversProp));

            console.log(servers);

            servers.push({ip:'111', port: 2222});

            const first_path = {
                servers: servers,
                selected: null,
            };

            return {
                servers: servers.data,
                maxServersInPath: 5,
                pathElements: [first_path],
            };
        },

        methods: {
            changeServer: function (index, event) {
                console.log(event);
                console.log('change');
            }
        },
    }
</script>

<style scoped>

</style>


Tell me why it doesn't work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-02-09
@arseniylebedev

v-on:change works.

Look for the problem elsewhere

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question