Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions AspNetCoreVueStarter.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
Expand All @@ -19,9 +19,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.2.0" />
<PackageReference Include="VueCliMiddleware" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.0.0" />
<PackageReference Include="VueCliMiddleware" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions ClientApp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ClientApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"date-fns": "^2.2.1",
"register-service-worker": "^1.6.2",
"vue": "^2.6.10",
"vue-class-component": "^7.1.0",
Expand Down
5 changes: 5 additions & 0 deletions ClientApp/src/filters/date.filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { format } from 'date-fns';

export default (date: Date) => {
return format(new Date(date), 'eeee, dd MMMM');
};
3 changes: 3 additions & 0 deletions ClientApp/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import App from './App.vue';
import router from './router';
import store from '@/store/index';
import './registerServiceWorker';
import dateFilter from '@/filters/date.filter';

Vue.config.productionTip = false;

Vue.filter('date', dateFilter);

new Vue({
vuetify,
router,
Expand Down
2 changes: 1 addition & 1 deletion ClientApp/src/models/Forecast.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class Forecast {
constructor(
public dateFormatted: Date,
public date: Date,
public temperatureC: number,
public temperatureF: number,
public summary: string,
Expand Down
45 changes: 26 additions & 19 deletions ClientApp/src/views/FetchData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
class="elevation-1"
>
<v-progress-linear v-slot:progress color="blue" indeterminate></v-progress-linear>
<template v-slot:items="props">
<td>{{ props.item.dateFormatted }}</td>
<td>{{ props.item.temperatureC }}</td>
<td>{{ props.item.temperatureF }}</td>
<td>{{ props.item.summary }}</td>
<template v-slot:item.date="{ item }">
<td>{{ item.date | date }}</td>
</template>
<template v-slot:item.temperatureC="{ item }">
<v-chip :color="getColor(item.temperatureC)" dark>{{ item.temperatureC }}</v-chip>
</template>
</v-data-table>
</v-col>
Expand Down Expand Up @@ -56,27 +56,34 @@ export default class FetchDataView extends Vue {
private errorMessage: string = 'Error while loading weather forecast.';
private forecasts: Forecast[] = [];
private headers = [
{ text: 'Date', value: 'dateFormatted' },
{ text: 'Date', value: 'date' },
{ text: 'Temp. (C)', value: 'temperatureC' },
{ text: 'Temp. (F)', value: 'temperatureF' },
{ text: 'Summary', value: 'summary' },
];

private created() {
this.fetchWeatherForecasts();
private getColor(temperature: number) {
if (temperature < 0) {
return 'blue';
} else if (temperature >= 0 && temperature < 30) {
return 'green';
} else {
return 'red';
}
}
private async created() {
await this.fetchWeatherForecasts();
}

private fetchWeatherForecasts() {
axios
.get<Forecast[]>('api/SampleData/WeatherForecasts')
.then((response) => {
this.forecasts = response.data;
})
.catch((e) => {
this.showError = true;
this.errorMessage = `Error while loading weather forecast: ${e.message}.`;
})
.finally(() => (this.loading = false));
private async fetchWeatherForecasts() {
try {
const response = await axios.get<Forecast[]>('api/WeatherForecast');
this.forecasts = response.data;
} catch (e) {
this.showError = true;
this.errorMessage = `Error while loading weather forecast: ${e.message}.`;
}
this.loading = false;
}
}
</script>
45 changes: 0 additions & 45 deletions Controllers/SampleDataController.cs

This file was deleted.

40 changes: 40 additions & 0 deletions Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AspNetCoreVueStarter.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace AspNetCoreVueStarter.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}
18 changes: 18 additions & 0 deletions Models/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AspNetCoreVueStarter.Models
{
public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
}
22 changes: 11 additions & 11 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;

namespace AspNetCoreVueStarter
{
Expand All @@ -17,8 +10,15 @@ public static void Main(string[] args)
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
public static IHostBuilder CreateWebHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
// Set properties and call methods on options
})
.UseStartup<Startup>();
});
}
}
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The repository contains an ASP.&#8203;NET Core + Vue.js starter template. The te

Original article how to create the starter template is available [here](https://medium.com/software-ateliers/asp-net-core-vue-template-with-custom-configuration-using-cli-3-0-8288e18ae80b).

[![Nuget](https://img.shields.io/nuget/v/SoftwareAteliers.AspNetCoreVueStarter.svg?style=flat&color=2196f3)](https://www.nuget.org/packages/aspnetcore-vuejs/)

> For ASP.NET Core 2.2 template use [release v1.1.0](https://github.com/SoftwareAteliers/asp-net-core-vue-starter/releases/tag/1.1.0)

---

## Table of Contents
Expand All @@ -23,10 +27,10 @@ Original article how to create the starter template is available [here](https://

## Used Technology Stack

**ASP.NET Core 2.2:**
**ASP.NET Core 3.0:**

* Web.API
* JavaScript Services middleware to integrate with client app
* Vue CLI and JavaScript Services middlewares to integrate with client app

**Vue.js with CLI 3.0 supporting optional integrations:**

Expand All @@ -41,7 +45,7 @@ Original article how to create the starter template is available [here](https://

## Prerequisites

* [.NET Core](https://www.microsoft.com/net/download/windows)
* [.NET Core](https://www.microsoft.com/net/download/windows) >= 3.0
* [NodeJS](https://nodejs.org/) >= 8.9
* [Vue CLI](https://cli.vuejs.org/) >= 3.0
* Your favourite editor (I prefer [VS Code](https://code.visualstudio.com/)), or VS 2017/19
Expand All @@ -62,7 +66,7 @@ or you can use .NET Core CLI templates:

* Initialize the project: `dotnet new vue -o MyProject`

## Scaffold Vue.js app with custom configuration
## (Optional) Scaffold Vue.js app with custom configuration

If you prefer to overwrite default Vue client app with custom settings, take the following steps:

Expand Down Expand Up @@ -93,6 +97,8 @@ You have two choices when it comes to how you prefer to run the app. You can eit

Browse to [http://localhost:5000](http://localhost:5000) for ASP.&#8203;NET Core + Vue app or browse to [http://localhost:8080](http://localhost:8080) for Vue app only.

![Application screenshot](./screenshot.png)

## Recommended plugin for debugging Vue

* Get Chrome DevTools for Vue.js [here](https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)
Expand All @@ -116,7 +122,7 @@ Special thanks to everyone who helped and contributed to this project!

## License

[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](/content/LICENSE)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://mit-license.org/)

Copyright &copy; 2018 - 2019 [Software Ateliers](https://github.com/SoftwareAteliers)

Expand Down
Loading