8000 Merge pull request #6 from john-cheesman/pass-origin-async-data · ferrywlto/vuejs-aspnetcore-ssr@14f18a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 14f18a1

Browse files
authored
Merge pull request #6 from john-cheesman/pass-origin-async-data
Pass context to asyncData to provide origin for vuex actions
2 parents 820405a + 9e4ee9c commit 14f18a1

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

ClientApp/components/Messages.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import Message from './Message.vue';
1212
export default {
1313
components: { Message },
1414
computed: mapGetters(['messages', 'lastFetchedMessageDate']),
15-
methods:
16-
mapActions(['fetchMessages']),
17-
asyncData ({ store }) {
18-
return store.dispatch('fetchInitialMessages')
15+
methods:
16+
mapActions(['fetchMessages']),
8000 17+
asyncData ({ store, context }) {
18+
return store.dispatch('fetchInitialMessages', context.origin)
1919
}
2020
}
2121
</script>

ClientApp/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default context => {
1111
}
1212
Promise.all(matchedComponents.map(Component => {
1313
if (Component.asyncData) {
14-
return Component.asyncData({ store })
14+
return Component.asyncData({ store, context })
1515
}
1616
}))
1717
.then(() => {

ClientApp/vuex/actions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import axios from 'axios'
22

3-
export const fetchInitialMessages = ({commit}) => {
3+
export const fetchInitialMessages = ({commit}, origin) => {
44
// this one will run on server so it need FQDN or server won't able to resolve the API address
5-
return axios.get('http://localhost:5000/initialMessages').then(response => {
5+
return axios.get(`${origin}/initialMessages`).then(response => {
66
commit('INITIAL_MESSAGES', response.data)
77
}).catch(err => {
88
console.log(err)
99
})
1010
}
1111

1212
export const fetchMessages = ({commit}, lastFetchedMessageDate) => {
13-
axios.post('http://localhost:5000/fetchMessages',{
13+
axios.post('/fetchMessages',{
1414
lastMessageDate : lastFetchedMessageDate
1515
})
1616
.then(response => {

0 commit comments

Comments
 (0)
0