Commit 94ef6f9f by Vladidas

Fix bugs

parent ff897493
# test #Build project
// Start WebSocket server.
> A Vue.js project ```
php artisan socket:start
```
## Build Setup // Start Laravel server.
```
php artisan serve
```
``` bash // Start VueJS SPA
# install dependencies ```
npm install npm vue dev
```
# serve with hot reload at localhost:8080 ##Technologies:
npm run dev - 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 { ...@@ -29,11 +29,6 @@ export default {
created () { created () {
this.isAuth = store.getters.isAuth this.isAuth = store.getters.isAuth
}, },
watch: {
title () {
document.title = this.title;
}
},
updated() updated()
{ {
this.isAuth = store.getters.isAuth 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 Vue from 'vue'
import App from './App.vue'
import store from './store/index' import store from './store/index'
import router from './router/index' import router from './router/index'
import App from './App.vue'
new Vue({ new Vue({
el: '#app', el: '#app',
render: h => h(App), render: h => h(App),
store, store,
router router
}); });
\ No newline at end of file
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
import Vue from 'vue'; import Vue from 'vue';
import axios from 'axios'; import axios from 'axios';
import UserForm from './UserForm'; import UserForm from './UserForm';
import config from './../../config/index';
Vue.component('user-form', UserForm); Vue.component('user-form', UserForm);
...@@ -38,10 +39,10 @@ export default { ...@@ -38,10 +39,10 @@ export default {
}) })
.then(response => { .then(response => {
if (response.status === 200) { if (response.status === 200) {
if(response.data.status == 1) { if(!response.data.errors) {
this.$router.push('/users') this.$router.push(config.usersHomePage)
} else { } else {
this.errors = response.data.errors this.errors = response.data.errors
} }
} }
}); });
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
</template> </template>
<script> <script>
import axios from 'axios' import axios from 'axios'
import config from './../../config/index';
export default { export default {
data () { data () {
...@@ -44,7 +45,7 @@ export default { ...@@ -44,7 +45,7 @@ export default {
.then(response => { .then(response => {
if (response.status === 200) { if (response.status === 200) {
if(response.data.status == 1) { if(response.data.status == 1) {
this.$router.push('/users') this.$router.push(config.usersHomePage)
} else { } else {
this.errors = response.data.errors this.errors = response.data.errors
} }
......
import Vue from 'vue' import Vue from "vue"
import config from "./../config/index"
/** Start socket. */
const socket = new WebSocket('ws://localhost:8888');
/** Send new message */ /** Send new message */
const emitter = new Vue({ 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){ send(message){
if (1 === socket.readyState) if (this.socket.readyState === 1) {
socket.send(message) this.socket.send(message)
} }
},
start(){
this.socket = new WebSocket(config.wsHost);
},
onMessage(){
this.socket.onmessage = function(msg){
emitter.$emit("message", msg.data)
};
},
onError(){
this.socket.onerror = function(err){
emitter.$emit("error", err)
};
},
} }
}); });
/** On message event. */
socket.onmessage = function(msg){
emitter.$emit("message", msg.data)
};
/** On error event. */
socket.onerror = function(err){
emitter.$emit("error", err)
};
export default emitter export default emitter
\ No newline at end of file
import Vue from 'vue' import Vue from 'vue'
import VueX from 'vuex' import VueX from 'vuex'
import router from './../router' import router from './../router'
import config from './../config/index'
Vue.use(VueX); Vue.use(VueX);
export default new VueX.Store({ export default new VueX.Store({
state: { state: {
host: 'http://localhost:8000', host: config.host,
// wsHost: 'ws://localhost:8888',
counter: 0, counter: 0,
token: null, token: null,
}, },
...@@ -20,7 +20,7 @@ export default new VueX.Store({ ...@@ -20,7 +20,7 @@ export default new VueX.Store({
localStorage.removeItem('user-token'); localStorage.removeItem('user-token');
if(!getters.isAuth) { if(!getters.isAuth) {
return router.push('/') return router.push(config.redirectIfLogout)
} }
} }
}, },
...@@ -29,7 +29,7 @@ export default new VueX.Store({ ...@@ -29,7 +29,7 @@ export default new VueX.Store({
state.token = token; state.token = token;
localStorage.setItem('user-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