├── global.json ├── Views ├── _ViewStart.cshtml ├── _ViewImports.cshtml ├── Shared │ ├── Error.cshtml │ └── _Layout.cshtml └── Home │ └── Index.cshtml ├── wwwroot └── favicon.ico ├── appsettings.json ├── ClientApp ├── components │ ├── app │ │ ├── app.ts │ │ └── app.vue.html │ ├── counter │ │ ├── counter.ts │ │ └── counter.vue.html │ ├── fetchdata │ │ ├── fetchdata.ts │ │ └── fetchdata.vue.html │ ├── todos │ │ ├── todos.vue.html │ │ └── todos.ts │ ├── home │ │ └── home.vue.html │ └── navmenu │ │ ├── navmenu.css │ │ └── navmenu.vue.html └── boot.ts ├── Models ├── Todo.cs └── WeatherForecast.cs ├── tsconfig.json ├── .vscode ├── tasks.json └── launch.json ├── Controllers ├── HomeController.cs ├── SampleDataController.cs └── TodoController.cs ├── web.config ├── Program.cs ├── package.json ├── AspCoreVue.csproj ├── webpack.config.vendor.js ├── webpack.config.js ├── Startup.cs └── .gitignore /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { "version": "1.0.3" } 3 | } 4 | -------------------------------------------------------------------------------- /Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaniJG/AspCoreVue/HEAD/wwwroot/favicon.ico -------------------------------------------------------------------------------- /Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using AspCoreVue 2 | @addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" 3 | @addTagHelper "*, Microsoft.AspNetCore.SpaServices" 4 | -------------------------------------------------------------------------------- /Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Error"; 3 | } 4 | 5 |

Error.

6 |

An error occurred while processing your request.

7 | -------------------------------------------------------------------------------- /appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
Loading...
6 | 7 | @section scripts { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ClientApp/components/app/app.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import { Component } from 'vue-property-decorator'; 3 | 4 | @Component({ 5 | components: { 6 | MenuComponent: require('../navmenu/navmenu.vue.html') 7 | } 8 | }) 9 | export default class AppComponent extends Vue { 10 | } 11 | -------------------------------------------------------------------------------- /ClientApp/components/counter/counter.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import { Component } from 'vue-property-decorator'; 3 | 4 | @Component 5 | export default class CounterComponent extends Vue { 6 | currentcount: number = 0; 7 | 8 | incrementCounter() { 9 | this.currentcount++; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Models/Todo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace ASPCoreVue.Models 7 | { 8 | public class Todo 9 | { 10 | public Guid Id { get; set; } 11 | public string Description { get; set; } 12 | public bool Done { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ClientApp/components/counter/counter.vue.html: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "experimentalDecorators": true, 5 | "module": "es2015", 6 | "moduleResolution": "node", 7 | "target": "es5", 8 | "sourceMap": true, 9 | "skipDefaultLibCheck": true, 10 | "types": ["requirejs"] 11 | }, 12 | "exclude": [ 13 | "bin", 14 | "node_modules" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /ClientApp/components/app/app.vue.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "0.1.0", 5 | "command": "dotnet", 6 | "isShellCommand": true, 7 | "args": [], 8 | "tasks": [ 9 | { 10 | "taskName": "build", 11 | "args": [ ], 12 | "isBuildCommand": true, 13 | "showOutput": "silent", 14 | "problemMatcher": "$msCompile" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace AspCoreVue.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | public IActionResult Index() 12 | { 13 | return View(); 14 | } 15 | 16 | public IActionResult Error() 17 | { 18 | return View(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - AspCoreVue 7 | 8 | 9 | 10 | 11 | @RenderBody() 12 | 13 | 14 | @RenderSection("scripts", required: false) 15 | 16 | 17 | -------------------------------------------------------------------------------- /Models/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace ASPCoreVue.Models 7 | { 8 | public class WeatherForecast 9 | { 10 | public string DateFormatted { get; set; } 11 | public int TemperatureC { get; set; } 12 | public string Summary { get; set; } 13 | 14 | public int TemperatureF 15 | { 16 | get 17 | { 18 | return 32 + (int)(TemperatureC / 0.5556); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Hosting; 7 | 8 | namespace AspCoreVue 9 | { 10 | public class Program 11 | { 12 | public static void Main(string[] args) 13 | { 14 | var host = new WebHostBuilder() 15 | .UseKestrel() 16 | .UseContentRoot(Directory.GetCurrentDirectory()) 17 | .UseIISIntegration() 18 | .UseStartup() 19 | .Build(); 20 | 21 | host.Run(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ClientApp/components/fetchdata/fetchdata.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import { Component } from 'vue-property-decorator'; 3 | 4 | interface WeatherForecast { 5 | dateFormatted: string; 6 | temperatureC: number; 7 | temperatureF: number; 8 | summary: string; 9 | } 10 | 11 | @Component 12 | export default class FetchDataComponent extends Vue { 13 | forecasts: WeatherForecast[] = []; 14 | 15 | mounted() { 16 | fetch('/api/SampleData/WeatherForecasts') 17 | .then(response => response.json() as Promise) 18 | .then(data => { 19 | this.forecasts = data; 20 | }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ClientApp/boot.ts: -------------------------------------------------------------------------------- 1 | import 'bootstrap'; 2 | import Vue from 'vue'; 3 | import VueRouter from 'vue-router'; 4 | Vue.use(VueRouter); 5 | 6 | const routes = [ 7 | { path: '/', component: require('./components/home/home.vue.html') }, 8 | { path: '/counter', component: require('./components/counter/counter.vue.html') }, 9 | { path: '/fetchdata', component: require('./components/fetchdata/fetchdata.vue.html') }, 10 | { path: '/todos', component: require('./components/todos/todos.vue.html') } 11 | ]; 12 | 13 | new Vue({ 14 | el: '#app-root', 15 | router: new VueRouter({ mode: 'history', routes: routes }), 16 | render: h => h(require('./components/app/app.vue.html')) 17 | }); 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "AspCoreVue", 3 | "version": "0.0.0", 4 | "devDependencies": { 5 | "@types/requirejs": "^2.1.28", 6 | "aspnet-webpack": "^1.0.27", 7 | "awesome-typescript-loader": "^3.0.0", 8 | "bootstrap": "^3.3.6", 9 | "css-loader": "^0.25.0", 10 | "event-source-polyfill": "^0.0.7", 11 | "extract-text-webpack-plugin": "^2.0.0-rc", 12 | "file-loader": "^0.9.0", 13 | "isomorphic-fetch": "^2.2.1", 14 | "jquery": "^3.1.1", 15 | "style-loader": "^0.13.1", 16 | "typescript": "^2.2.1", 17 | "url-loader": "^0.5.7", 18 | "vue": "^2.2.2", 19 | "vue-loader": "^11.1.4", 20 | "vue-property-decorator": "^5.0.1", 21 | "vue-router": "^2.3.0", 22 | "vue-template-compiler": "^2.2.2", 23 | "webpack": "^2.2.0", 24 | "webpack-hot-middleware": "^2.12.2" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ClientApp/components/todos/todos.vue.html: -------------------------------------------------------------------------------- 1 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ClientApp/components/fetchdata/fetchdata.vue.html: -------------------------------------------------------------------------------- 1 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Controllers/SampleDataController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using ASPCoreVue.Models; 7 | 8 | namespace AspCoreVue.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | public class SampleDataController : Controller 12 | { 13 | private static string[] Summaries = new[] 14 | { 15 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 16 | }; 17 | 18 | [HttpGet("[action]")] 19 | public IEnumerable WeatherForecasts() 20 | { 21 | var rng = new Random(); 22 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 23 | { 24 | DateFormatted = DateTime.Now.AddDays(index).ToString("d"), 25 | TemperatureC = rng.Next(-20, 55), 26 | Summary = Summaries[rng.Next(Summaries.Length)] 27 | }); 28 | } 29 | 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Controllers/TodoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Concurrent; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using ASPCoreVue.Models; 8 | 9 | namespace AspCoreVue.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | public class TodoController : Controller 13 | { 14 | private static ConcurrentBag todos = new ConcurrentBag { 15 | new Todo { Id = Guid.NewGuid(), Description = "Learn Vue" } 16 | }; 17 | 18 | [HttpGet()] 19 | public IEnumerable GetTodos() 20 | { 21 | return todos.Where(t => !t.Done); 22 | } 23 | 24 | [HttpPost()] 25 | public Todo AddTodo([FromBody]Todo todo) 26 | { 27 | todo.Id = Guid.NewGuid(); 28 | todo.Done = false; 29 | todos.Add(todo); 30 | return todo; 31 | } 32 | 33 | [HttpDelete("{id}")] 34 | public ActionResult CompleteTodo(Guid id) 35 | { 36 | var todo = todos.SingleOrDefault(t => t.Id == id); 37 | if (todo == null) return NotFound(); 38 | 39 | todo.Done = true; 40 | return StatusCode(204); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /AspCoreVue.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp1.1 4 | true 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | %(DistFiles.Identity) 29 | PreserveNewest 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /ClientApp/components/home/home.vue.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ClientApp/components/todos/todos.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import { Component } from 'vue-property-decorator'; 3 | 4 | interface TodoItem { 5 | description: string; 6 | done: boolean; 7 | id: string; 8 | } 9 | 10 | @Component 11 | export default class TodoComponent extends Vue { 12 | todos: TodoItem[]; 13 | newItemDescription: string; 14 | 15 | data() { 16 | return { 17 | todos: [], 18 | newItemDescription: null 19 | }; 20 | } 21 | 22 | mounted() { 23 | fetch('/api/todo') 24 | .then(response => response.json() as Promise) 25 | .then(data => { 26 | this.todos = data; 27 | }); 28 | } 29 | 30 | addItem(event){ 31 | if(event) event.preventDefault(); 32 | 33 | fetch('/api/todo', { 34 | method: 'post', 35 | body: JSON.stringify({description: this.newItemDescription}), 36 | headers: new Headers({ 37 | 'Accept': 'application/json', 38 | 'Content-Type': 'application/json' 39 | }) 40 | }) 41 | .then(response => response.json() as Promise) 42 | .then((newItem) => { 43 | this.todos.push(newItem); 44 | this.newItemDescription = null; 45 | }); 46 | } 47 | 48 | completeItem(item: TodoItem){ 49 | fetch(`/api/todo/${item.id}`, { 50 | method: 'delete', 51 | headers: new Headers({ 52 | 'Accept': 'application/json', 53 | 'Content-Type': 'application/json' 54 | }) 55 | }) 56 | .then(() => { 57 | this.todos = this.todos.filter((t) => t.id !== item.id); 58 | }); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ClientApp/components/navmenu/navmenu.css: -------------------------------------------------------------------------------- 1 | .main-nav li .glyphicon { 2 | margin-right: 10px; 3 | } 4 | 5 | /* Highlighting rules for nav menu items */ 6 | .main-nav li a.router-link-active, 7 | .main-nav li a.router-link-active:hover, 8 | .main-nav li a.router-link-active:focus { 9 | background-color: #4189C7; 10 | color: white; 11 | } 12 | 13 | /* Keep the nav menu independent of scrolling and on top of other items */ 14 | .main-nav { 15 | position: fixed; 16 | top: 0; 17 | left: 0; 18 | right: 0; 19 | z-index: 1; 20 | } 21 | 22 | @media (max-width: 767px) { 23 | /* On small screens, the nav menu spans the full width of the screen. Leave a space for it. */ 24 | body { 25 | padding-top: 50px; 26 | } 27 | } 28 | 29 | @media (min-width: 768px) { 30 | /* On small screens, convert the nav menu to a vertical sidebar */ 31 | .main-nav { 32 | height: 100%; 33 | width: calc(25% - 20px); 34 | } 35 | .main-nav .navbar { 36 | border-radius: 0px; 37 | border-width: 0px; 38 | height: 100%; 39 | } 40 | .main-nav .navbar-header { 41 | float: none; 42 | } 43 | .main-nav .navbar-collapse { 44 | border-top: 1px solid #444; 45 | padding: 0px; 46 | } 47 | .main-nav .navbar ul { 48 | float: none; 49 | } 50 | .main-nav .navbar li { 51 | float: none; 52 | font-size: 15px; 53 | margin: 6px; 54 | } 55 | .main-nav .navbar li a { 56 | padding: 10px 16px; 57 | border-radius: 4px; 58 | } 59 | .main-nav .navbar a { 60 | /* If a menu item's text is too long, truncate it */ 61 | width: 100%; 62 | white-space: nowrap; 63 | overflow: hidden; 64 | text-overflow: ellipsis; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ClientApp/components/navmenu/navmenu.vue.html: -------------------------------------------------------------------------------- 1 | 41 | 42 |