🚧 Site > Add Vue store

This commit is contained in:
brunosimon
2017-08-04 09:05:44 +02:00
parent 1aa3e5f135
commit eec6f8a796
15 changed files with 114 additions and 23 deletions
+17 -16
View File
@@ -1,32 +1,33 @@
import socketIoClient from 'socket.io-client'
import Connexion from '@/components/connexion'
import ProjectsHub from '@/components/projects-hub'
export default
{
name: 'application',
components:
{
Connexion,
ProjectsHub
},
data()
{
return {
counter: 0,
projects: { type: Object, value: {} }
counter: 0
}
},
computed:
{
projects()
{
return this.$store.state.projects
}
},
mounted()
{
const socketUrl = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/projects`
const socket = socketIoClient(socketUrl)
socket.on('connect', () =>
{
console.log('connected')
})
socket.on('update_projects', (data) =>
{
this.projects = data.all
})
window.setInterval(() =>
{
this.counter++
@@ -1,2 +0,0 @@
#application
background #f0f
@@ -1,6 +1,5 @@
<div id="application">
{{ counter }}
<div v-for="project in projects">
{{ project.name }}
</div>
<connexion></connexion>
<projects-hub></projects-hub>
</div>
+3
View File
@@ -0,0 +1,3 @@
<template src="./template.html"></template>
<script src="./script.js"></script>
<style src="./style.styl" lang="stylus"></style>
+22
View File
@@ -0,0 +1,22 @@
import socketIoClient from 'socket.io-client'
export default
{
name: 'connexion',
created()
{
this.url = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/projects`
this.socket = socketIoClient(this.url)
this.socket.on('connect', () =>
{
console.log('connected')
})
this.socket.on('update_projects', (data) =>
{
this.$store.commit('updateProjects', data.all)
})
}
}
@@ -0,0 +1,2 @@
<div>
</div>
@@ -0,0 +1,3 @@
<template src="./template.html"></template>
<script src="./script.js"></script>
<style src="./style.styl" lang="stylus"></style>
@@ -0,0 +1,17 @@
export default
{
name: 'projects-hub',
computed:
{
projects()
{
return this.$store.state.projects
}
},
created()
{
}
}
@@ -0,0 +1,5 @@
<div>
<a :href="project.slug" v-for="project in projects">
{{ project.name }}
</a>
</div>