forked from buefy/buefy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
69 lines (60 loc) · 1.61 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
<div id="app">
<vue-progress-bar/>
<router-view/>
</div>
</template>
<script>
import Clipboard from 'clipboard'
export default {
name: 'Buefy',
data() {
return {
clipboard: null
}
},
methods: {
setupClipboardControls() {
// Destroy clipboard instance if there's any
this.clipboard && this.clipboard.destroy()
this.clipboard = new Clipboard('.copy-code', {
target: (trigger) => trigger.parentElement.parentElement.querySelector('code')
})
this.clipboard.on('success', (e) => {
this.$buefy.toast.open('Copied to clipboard!')
})
this.clipboard.on('error', (e) => {
this.$buefy.toast.open({
message: 'Error while copying to clipboard :(',
type: 'is-danger'
})
})
}
},
created() {
this.$Progress.start()
this.$router.beforeEach((to, from, next) => {
this.$Progress.start()
next()
})
this.$router.afterEach((to, from) => {
this.$Progress.finish()
})
this.setupClipboardControls()
},
mounted() {
this.$Progress.finish()
},
beforeDestroy() {
// Destroy clipboard instance if there's any
this.clipboard && this.clipboard.destroy()
},
beforeRouteUpdate(to, from, next) {
this.setupClipboardControls()
next()
}
}
</script>
<style lang="scss">
@import "./assets/scss/main.scss";
</style>