0
私は思っていますが、あなたの助けが必要です。 私はを作成しています。Axios Real Time(毎回Reload everytime)によって通知される通知コンポーネントはですが、私はそれを作るのが紛らわしいです。リアルタイムで通知のコンポーネントにAPIを取得する - NuxtJS
マイ通知コンポーネント:
<template>
<ul class="tab-content">
<notification-item></notification-item>
</ul>
</template>
<script>
import ItemNotification from '~/components/header/NotificationItem.vue'
export default {
components: {
'notification-item': ItemNotification
},
created() {
this.$store.dispatch('getNotification')
}
}
</script>
モジュールの通知:/store/notification.js:。
import api from '~/plugins/axios'
const state =() => {
return {
notifications: null
}
}
const actions = {
getNotification ({commit}, config) {
api.get(`/notifications/`, config)
.then(response => {
commit('GET_NOTIFICATION', response.data)
})
}
}
const getters = {}
const mutations = {
GET_NOTIFICATION (state, notifications) {
state.notifications = notifications
}
}
export default {
state,
actions,
getters,
mutations
}
このラインこの$のstore.dispatch( 'getNotification')しません作業?どのようにして最善の方法でそれをやり遂げることができますか、Githubのサンプルプロジェクトがありますか?私を助けてください !!!
そうです:あなたは、セットアップ、次のようにいつでもルート変更と呼ばれます
$route
財産上のウォッチャーをすることができます :だから
created()
フックEDITでアクションを派遣します。できます。しかし、私はこの問題を手伝ってください。どうすれば、この通知コンポーネントは常にリアルタイムのGetNotificationsメソッドをリロードできますか? –
@FeedGitリロードメソッドとはどういう意味ですか? –
Facebookの通知同様、URLを変更するとリロードされます! –