Skip to content

Instantly share code, notes, and snippets.

@havvg
Created June 3, 2016 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havvg/b6a3a81f88f53a9215ac328db34d1369 to your computer and use it in GitHub Desktop.
Save havvg/b6a3a81f88f53a9215ac328db34d1369 to your computer and use it in GitHub Desktop.
let eventBus = new Vue()
new Vue({
el: '#application',
replace: true,
template: '<app :event-bus="eventBus" :websocket-url="websocketUrl"></app>',
data: {
eventBus: eventBus,
websocketUrl: websocketUrl
}
});
<template>
<div>
<log-entry v-for="entry in entries" :entry="entry" :event-bus="eventBus"></log-entry>
</div>
</template>
<script>
import LogEntry from './components/log-entry.vue'
import {levels} from './data/log-levels.js'
export default {
props: [
'eventBus',
'websocketUrl'
],
data() {
return {
websocket: null,
entries: []
}
},
methods: {
removeEntry(entry) {
// ..
}
},
created() {
this.eventBus.$on('remove-entry', this.removeEntry)
},
components: {
LogEntry
}
}
</script>
<template>
<div>
<a href="#" @click="removeEntry(entry)"><i class="fa fa-remove"></i></a>
</div>
</template>
<script>
export default {
props: [
'entry',
'eventBus'
],
methods: {
removeEntry: function(entry) {
this.eventBus.$emit('remove-entry', entry)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment