File tree 8 files changed +101
-3
lines changed
8 files changed +101
-3
lines changed Original file line number Diff line number Diff line change 1
1
import Vue from 'vue' ;
2
2
import App from './components/App.vue' ;
3
-
3
+ import store from './vuex/store.js' ;
4
4
const app = new Vue ( {
5
+ store,
5
6
...App //... is spread operator if App is Array; is rest(remaining) properties if App is Object
6
7
} ) ;
7
8
Original file line number Diff line number Diff line change
1
+
2
+ <script >
3
+ import { mapGetters , mapActions } from ' vuex' ;
4
+ import Message from ' ./Message.vue' ;
5
+ export default {
6
+ components: { Message },
7
+ computed: mapGetters ([' messages' , ' lastFetchedMessageDate' ]),
8
+ methods: mapActions ([' fetchMessages' ]),
9
+ created () {
10
+ return this .$store .dispatch (' fetchInitialMessages' )
11
+ }
12
+ }
13
+ </script >
14
+
1
15
<template >
2
16
<div >
3
17
<h1 >Hello from Vue#!!!#</h1 >
18
+ <Message v-for =" (msg, index) in messages" :message =" msg" :key =" index" />
19
+ <button @click =" fetchMessages(lastFetchedMessageDate)" >Fetch a message</button >
4
20
</div >
5
- </template >
21
+ </template >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div >
3
+ <h2 >{{ message.title }}</h2 >
4
+ <p >{{ message.text }}</p >
5
+ </div >
6
+ </template >
7
+
8
+ <script >
9
+ export default {
10
+ props: [' message' ]
11
+ }
12
+ </script >
Original file line number Diff line number Diff line change
1
+ import axios from 'axios' ;
2
+
3
+ export const fetchInitialMessages = ( { commit } ) => {
4
+ axios . get ( 'initialMessages' ) . then ( response => {
5
+ commit ( "INITIAL_MESSAGES" , response . data ) ;
6
+ } ) . catch ( err => {
7
+ console . log ( err ) ;
8
+ } ) ;
9
+ } ;
10
+
11
+ export const fetchMessages = ( { commit } , lastFetchedMessageDate ) => {
12
+ axios . get ( '/fetchMessages?lastFetchedMessageDate=' + lastFetchedMessageDate )
13
+ . then ( response => {
14
+ commit ( "FETCH_MESSAGES" , response . data ) ;
15
+ } ) . catch ( err => {
16
+ console . log ( err ) ;
17
+ } ) ;
18
+ } ;
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue' ;
2
+ import Vuex from 'vuex' ;
3
+ import { fetchInitialMessages , fetchMessages } from './actions' ;
4
+ import minBy from 'lodash/minBy' ;
5
+
6
+ Vue . use ( Vuex ) ;
7
+
8
+ const store = new Vuex . Store ( {
9
+ state : { messages : [ ] , lastFetchedMessageDate : - 1 } ,
10
+
11
+ mutations : {
12
+ INITIAL_MESSAGES : ( state , payload ) => {
13
+ state . messages = payload . messages ;
14
+ state . lastFetchedMessageDate = payload . lastFetchedMessageDate ;
15
+ } ,
16
+ FETCH_MESSAGES : ( state , payload ) => {
17
+ state . messages = state . messages . concat ( payload ) ;
18
+ state . lastFetchedMessageDate = minBy ( state . messages , 'date' ) . date ;
19
+ }
20
+ } ,
21
+ getters : {
22
+ messages : state => state . messages ,
23
+ lastFetchedMessageDate : state => state . lastFetchedMessageDate
24
+ } ,
25
+ actions : {
26
+ fetchInitialMessages,
27
+ fetchMessages
28
+ }
29
+ } ) ;
30
+
31
+ export default store ;
Original file line number Diff line number Diff line change
1
+ This repository is a clone from Stu Ratcliffe [ Server rendering Vue.js applications with ASP.NET Core] ( https://github.com/sturatcliffe/VueDotnetSSR )
2
+
3
+ Following his articile and trying to have some write up. (e.g. using latest packages in package.json)
4
+
5
+ ## Packages used:
6
+ - lodash <- similiar to numpy in Python
7
+ - axios <- Promise based HTTP client for the browser and Node.js
8
+ - vuex <- Vue variant of Flux implementation, just like Redux in React
9
+ ### Working with data:
10
+ - .Net part
11
+ 1 . Message.cs
12
+ 2 . FakeMessageStore.cs
13
+ 3 . ClientState.cs
14
+ - Vue part
15
+ 0 . (create ClientApp/vuex folder)
16
+ 1 . ClientApp/vuex/action.js
17
+ 2 . ClientApp/vuex/store.js
Original file line number Diff line number Diff line change 10
10
"license" : " MIT" ,
11
11
"private" : true ,
12
12
"dependencies" : {
13
- "vue" : " ^2.5.8"
13
+ "vue" : " ^2.5.8" ,
14
+ "vuex" : " ^3.0.1" ,
15
+ "lodash" : " ^4.17.4" ,
16
+ "axios" : " ^0.17.1"
14
17
},
15
18
"devDependencies" : {
16
19
"babel-core" : " ^6.26.0" ,
You can’t perform that action at this time.
0 commit comments