This repository is a clone from Stu Ratcliffe Server rendering Vue.js applications with ASP.NET Core
Following his articile and trying to have some write up. (e.g. using latest packages in package.json)
if Webpack is not installed yet:
npm install -g webpack
dotnet restore
npm install
webpack
dotnet run
- lodash <- similiar to numpy in Python, utilies library for manipulating array/object.
- axios <- Promise based HTTP client for the browser and Node.js, think of $.ajax() if you come from jQuery world
- vuex <- Vue variant of Flux implementation, just like Redux in React
- .Net part
- Message.cs
- FakeMessageStore.cs
- ClientState.cs
- Vue part
0. (create ClientApp/vuex folder)
- ClientApp/vuex/action.js
- ClientApp/vuex/store.js
- Move to ClientApp/components
- Dashboard.vue
- Messages.vue
- Modify App.vue
- create ClientApp/router folder
- Move to ClientApp/router
- index.js
- Move back to ClientApp folder
- Modify app.js
- Move back to .
- Modify Startup.cs
Here we try to modify the implementation order different from the original post. We are going to add the loading indicator before implementing the Server Side Rendering. To simulate timely API call form remote server, we add the following line in HomeController.cs:
public JsonResult initialMessages(){
//Added to simulate initial loading from remote server
Thread.Sleep(2000);
...
}
-
Add nprogess in package.json dependency:
"dependencies": { "vue": "^2.5.8", "vuex": "^3.0.1", "vue-router": "^3.0.1", "lodash": "^4.17.4", "axios": "^0.17.1", "nprogress": "^0.2.0" }
-
Add style-loader and css-loader to webpack.config:
{ test: /\.css$/, loader: "style-loader!css-loader" }
-
Modify ClientApp/vuex/actions.js, add
NProgress.start()
andNProgress.done()
before and after axios remote call.