Commit 94ef6f9f by Vladidas

Fix bugs

parent ff897493
# test
> A Vue.js project
#Build project
// Start WebSocket server.
```
php artisan socket:start
```
## Build Setup
// Start Laravel server.
```
php artisan serve
```
``` bash
# install dependencies
npm install
// Start VueJS SPA
```
npm vue dev
```
# serve with hot reload at localhost:8080
npm run dev
##Technologies:
- Laravel: 5.6.39
- VueJS: 2.5.22
- WebSocket: Ratchet
# build for production with minification
npm run build
```
For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader).
/////////////////////
//And keep a smile!//
/////////////////////
```
\ No newline at end of file
......@@ -29,11 +29,6 @@ export default {
created () {
this.isAuth = store.getters.isAuth
},
watch: {
title () {
document.title = this.title;
}
},
updated()
{
this.isAuth = store.getters.isAuth
......
export default {
host: 'http://localhost:8000',
wsHost: 'ws://localhost:8888',
redirectIfAuth: '/admin/home',
redirectIfLogout: '/',
usersHomePage: '/users'
}
\ No newline at end of file
import Vue from 'vue'
import App from './App.vue'
import store from './store/index'
import router from './router/index'
import App from './App.vue'
new Vue({
el: '#app',
......
......@@ -12,6 +12,7 @@
import Vue from 'vue';
import axios from 'axios';
import UserForm from './UserForm';
import config from './../../config/index';
Vue.component('user-form', UserForm);
......@@ -38,8 +39,8 @@ export default {
})
.then(response => {
if (response.status === 200) {
if(response.data.status == 1) {
this.$router.push('/users')
if(!response.data.errors) {
this.$router.push(config.usersHomePage)
} else {
this.errors = response.data.errors
}
......
......@@ -11,6 +11,7 @@
<script>
import axios from 'axios'
import config from './../../config/index';
export default {
data () {
......@@ -44,7 +45,7 @@ export default {
.then(response => {
if (response.status === 200) {
if(response.data.status == 1) {
this.$router.push('/users')
this.$router.push(config.usersHomePage)
} else {
this.errors = response.data.errors
}
......
import Vue from 'vue'
/** Start socket. */
const socket = new WebSocket('ws://localhost:8888');
import Vue from "vue"
import config from "./../config/index"
/** Send new message */
const emitter = new Vue({
methods:{
data: {
socket: null
},
created() {
/** Start socket. */
this.start();
/** On message event. */
this.onMessage();
/** On error event. */
this.onError();
},
methods: {
send(message){
if (1 === socket.readyState)
socket.send(message)
if (this.socket.readyState === 1) {
this.socket.send(message)
}
}
});
/** On message event. */
socket.onmessage = function(msg){
},
start(){
this.socket = new WebSocket(config.wsHost);
},
onMessage(){
this.socket.onmessage = function(msg){
emitter.$emit("message", msg.data)
};
/** On error event. */
socket.onerror = function(err){
};
},
onError(){
this.socket.onerror = function(err){
emitter.$emit("error", err)
};
};
},
}
});
export default emitter
\ No newline at end of file
import Vue from 'vue'
import VueX from 'vuex'
import router from './../router'
import config from './../config/index'
Vue.use(VueX);
export default new VueX.Store({
state: {
host: 'http://localhost:8000',
// wsHost: 'ws://localhost:8888',
host: config.host,
counter: 0,
token: null,
},
......@@ -20,7 +20,7 @@ export default new VueX.Store({
localStorage.removeItem('user-token');
if(!getters.isAuth) {
return router.push('/')
return router.push(config.redirectIfLogout)
}
}
},
......@@ -29,7 +29,7 @@ export default new VueX.Store({
state.token = token;
localStorage.setItem('user-token', token);
return router.push('/admin/home')
return router.push(config.redirectIfAuth)
}
},
});
\ No newline at end of file
// Start WebSocket server.
php artisan socket:start
// Start Laravel server.
php artisan serve
// Start VueJS SPA
npm vue dev
/////////////////////
//And keep a smile!//
/////////////////////
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment