added ws base code
This commit is contained in:
80
src/components/Test.vue
Normal file
80
src/components/Test.vue
Normal file
@@ -0,0 +1,80 @@
|
||||
<!-- components/Profile.vue -->
|
||||
<template>
|
||||
<div>
|
||||
<h1>Toller Test</h1>
|
||||
<span>{{ $socket.connected ? 'Connected' : 'Disconnected' }}</span>
|
||||
<button v-if="$socket.connected" @click="disconnectWebsocket">Disconnect</button>
|
||||
<button v-else="$socket.connected" @click="connectWebsocket">Connect</button>
|
||||
<p>
|
||||
<button v-if="$socket.connected" @click="sendWsMessage('Tolle Test Nachricht')">Send Message</button>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {EventBus} from '@/utils';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
email: '',
|
||||
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
changeLocale(locale) {
|
||||
this.$i18n.locale = locale;
|
||||
// Vue.$moment.locale(locale);
|
||||
},
|
||||
sendWsMessage(msg){
|
||||
console.log("sending msg: "+ msg);
|
||||
this.$socket.client.emit('my_event', msg, (resp) => {
|
||||
console.log(resp);
|
||||
});
|
||||
},
|
||||
connectWebsocket(){
|
||||
this.$socket.client.connect();
|
||||
},
|
||||
disconnectWebsocket(){
|
||||
this.$socket.client.disconnect();
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$socket.client.on('my_event', (msg) => {
|
||||
console.log(msg);
|
||||
});
|
||||
this.$socket.client.on('connect', (msg) => {
|
||||
console.log("connected");
|
||||
console.log(msg);
|
||||
});
|
||||
|
||||
//this.$socket.$unsubscribe('even_name');
|
||||
|
||||
},
|
||||
beforeDestroy() {
|
||||
EventBus.$off('failedLoadingProfile');
|
||||
},
|
||||
computed: {
|
||||
profile() {
|
||||
return this.$store.state.profile;
|
||||
},
|
||||
access_token() {
|
||||
return this.$store.state.access_token;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.error-msg {
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
}
|
||||
.lang-btn {
|
||||
padding: 15px;
|
||||
border: 2px solid green;
|
||||
font-size: 18px;
|
||||
margin: 15px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user