0

So here is my code. When I press the button with mouse it reloads page but, when I press enter key its not refreshing. Any ideas how to do it?

 <template lang="html">

        <div class="chat-composer">

        <input maxlength="180" type="text" placeholder="mesajınızı yazınız"  v-model="messageText" @keyup.enter="sendMessage">i

        <button class="btn btn-primary" @click="sendMessage" onClick="window.location.reload();>Gönder</button>
        </div>

    </template>

here is full the code I use. So im not the expert.. I need help about it

<template lang="html">
    <div class="chat-composer">
    <input maxlength="180" type="text" placeholder="mesajınızı yazınız"  v-model="messageText"
    @keyup.enter="sendMessage">
    <button class="btn btn-primary" @click="sendMessage" onClick="window.location.reload();"
    >Gönder</button>
    </div>
</template>

<script>

    export default {
        data() {
            return {
                messageText: ''
            }
        },
        methods: {
            sendMessage(){
                this.$emit('messagesent',{
                message: this.messageText,
                user: {
                    name: $('.navbar-right .dropdown-toggle').text()
                }
                });
                this.messageText = '';
            },

        },

    }
</script>
Berke
  • 81
  • 2
  • 12

1 Answers1

1

You are using Vue.js, if so you can do something like this

<button class="btn btn-primary" v-on:keyup.enter="window.location.reload()" 
 @click="sendMessage" onClick="window.location.reload();>Gönder</button>

You can check the Key Modifiers here the https://v2.vuejs.org/v2/guide/events.html

tony19
  • 125,647
  • 18
  • 229
  • 307
Taha Azzabi
  • 2,392
  • 22
  • 31
  • I think we are close to the end. Mouse click works but , enter is still not working.. – Berke Jan 30 '18 at 19:13
  • I tried many different combinations... none of them is working.. peh any ideas now? – Berke Jan 30 '18 at 19:20
  • you can also use `@keypress.enter="something"` , but i wonder why you need to refresh page that will en all websocket connexion if you have it, and it will refresh the state and the reactive data if you don't use persist – Taha Azzabi Jan 30 '18 at 19:37
  • so its like a real time chat normally(which is not working in my case), so that s why its not refreshing the page. – Berke Jan 30 '18 at 19:37