forked from loburets/laravel-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArticle-item.vue
61 lines (54 loc) · 1.83 KB
/
Article-item.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
<template>
<div class="panel panel-default">
<preloader v-show="!loaded"></preloader>
<div class="panel-heading">{{ article.name }}</div>
<div class="panel-body">
{{ article.text }}
</div>
<div class="container-fluid row_btns">
<button class="btn btn-primary" @click="deleteArticle(article.id)" v-if="authorized">Delete</button>
<router-link :to="{ name: 'articleEdit', params: { id: article.id }}" class="btn btn-primary" v-if="authorized">Edit</router-link>
<router-link :to="{ name: 'article', params: { id: article.id }}" class="btn btn-primary">Show</router-link>
</div>
</div>
</template>
<script>
import { DELETE_ARTICLE_ACTION } from 'store/article/actions'
import { ADD_MESSAGE_MUTATION } from 'store/message/mutations'
import router from 'router'
import { mapState } from 'vuex'
import preloader from 'components/preloader'
export default {
components: { preloader },
props: {
article: {
type: Object,
required: true,
},
},
data() {
return {
loaded: true
}
},
computed: mapState({
authorized: state => state.User.authorized,
}),
methods: {
deleteArticle(id) {
this.loaded = false
this.$store.dispatch('Article/' + DELETE_ARTICLE_ACTION, id).then((response) => {
this.$store.commit('Message/' + ADD_MESSAGE_MUTATION, 'The article has been deleted')
this.loaded = true
}).catch((error) => {
this.loaded = true
})
},
},
}
</script>
<style scoped>
.panel {
position: relative;
}
</style>