.Net Core Vue Qucik Start

This is a ASP.NET Core 3.0 project seamlessly integrationed with Vue.js template.

A complaint from Microsoft officials:

As far as I'm aware, we don't have plans to introduce Vue-specific features. This isn't because we have anything against Vue, but rather just to limit the growth in the number of frameworks that we're maintaining support for. The dev team only has a finite capacity for handling third-party concepts, and last year we made the strategic choice to focus on only Angular and React.

Microsoft won't stop our enthusiasm for vuejs

The Microsoft's dev team only has a finite capacity for handling third-party concepts, but we chinese men don't. Men can never say no.

Let's Set Sail

1. Create a new project with react template

  • You can use Visual Studio to create a project with React.js:

  • Or execute dotnet new react command in Command Line Tools:

2. Change Reactjs template to Vuejs template

  • Remove ClientApp folder:

  • Create new vue template project in root folder:

  • Rename all ClientApp folder to our vue project name:

Startup.cs

    public void ConfigureServices(IServiceCollection services)
{
... services.AddSpaStaticFiles(configuration =>
{
// configuration.RootPath = "ClientApp/build";
configuration.RootPath = "admin/build";
});
} public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
... app.UseSpa(spa =>
{
// spa.Options.SourcePath = "ClientApp";
spa.Options.SourcePath = "admin"; ...
});
}

NetCoreVue.csproj

  <PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<!-- <SpaRoot>ClientApp\</SpaRoot> -->
<SpaRoot>admin\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
</PropertyGroup>
  • Add VueCliMiddleware package from nuget:

Run dotnet add package VueCliMiddleware command in the Package Manager Console.

  • Change ReactDevelopmentServer to VueCli:
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
... app.UseSpa(spa =>
{
spa.Options.SourcePath = "admin"; if (env.IsDevelopment())
{
// spa.UseReactDevelopmentServer(npmScript: "start");
spa.UseVueCli();
}
});
}
  • Change React build floder 'build' to Vue build folder 'dist':

Startup.cs

    public void ConfigureServices(IServiceCollection services)
{
... services.AddSpaStaticFiles(configuration =>
{
// configuration.RootPath = "admin/build";
configuration.RootPath = "admin/dist";
});
}

NetCoreVue.csproj

    <ItemGroup>
<!-- <DistFiles Include="$(SpaRoot)build\**" /> -->
<DistFiles Include="$(SpaRoot)dist\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
  • Run to test

Run dotnet run in Command Line Tools to run the app.

3. Case will be in the end

  • Install axios plugin:

Run vue add axios command in Command Line Tools to install axios.

  • Run vue add router command in Command Line Tools to install vue-router.

  • add WeatherForecast.vue in views folder:
<template>
<div class="weather">
<table className='table table-striped' aria-labelledby="tabelLabel">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
<tr v-for="(forecast,index) in forecasts" :key="forecast.date">
<td>{{forecast.date}}</td>
<td>{{forecast.temperatureC}}</td>
<td>{{forecast.temperatureF}}</td>
<td>{{forecast.summary}}</td>
</tr>
</tbody>
</table>
</div>
</template> <script>
export default {
name: 'WeatherForecast',
data() {
return {
forecasts:[]
};
},
created() {
this.axios.get("/weatherforecast").then(res => {
// console.log(res.data);
this.forecasts = res.data;
});
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped> body{
text-align:center;
} .weather {
margin: 0 auto;
}
</style>
  • Add a new router:
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
...
{
path: '/weather',
name: 'weather',
component: () => import('./views/WeatherForecast.vue')
}
]
})
  • Run to view the last result:

Enjoy it!

.Net Core Vue Qucik Start的更多相关文章

  1. ASP.NET Core + Vue.js 开发

    1.新建 项目文件夹 pro,在 VS CODE 打开终端,输入dotnet new mvc 命令,新建asp.net core项目. 2.在Startup.cs添加webpack的引用与配置 usi ...

  2. .Net Core+Vue.js+ElementUI 实现前后端分离

    .Net Core+Vue.js+ElementUI 实现前后端分离 Tags: Vue 架构 前端采用:Vue.js.Element-UI.axios 后端采用:.Net Core Mvc 本项目是 ...

  3. Core + Vue 后台管理基础框架0——开篇

    1.背景 最近,打算新开个项目,鉴于团队技术栈,选型.net core + vue,前后端分离.本打算捡现成的轮子的,github上大致逛了逛,总发现这样那样的不太适合心中那些“完美实践”,例如:Ab ...

  4. 基于TeamCity的asp.net mvc/core,Vue 持续集成与自动部署

    一 Web Server(Windows)端的配置 1.配置IIS,重要的是管理服务 1.1 配置FTP(前端NPM项目需要) 该步骤略,如果是在阿里云ESC上,需要开启端口21(用来FTP认证握手) ...

  5. 使用.Net Core + Vue + IdentityServer4 + Ocelot 实现一个简单的DEMO +源码

    运行环境 Vue 使用的是D2admin: https://doc.d2admin.fairyever.com/zh/ Github地址:https://github.com/Fengddd/Perm ...

  6. .Net Core,VUE,VS Code,Sql Sugar,Element UI学习笔记

    1..Net Core的目的是跨平台,并主要目标是作为服务端开发使用.从3.0开始,引入了Winfrom和WPF. 2..Net Core可以引用.Net Framework生成的dll和exe,不限 ...

  7. 企业项目实战 .Net Core + Vue/Angular 分库分表日志系统一 | 前言

    教程预览 01 | 前言 02 | 简单的分库分表设计 03 | 控制反转搭配简单业务 04 | 强化设计方案 05 | 完善业务自动创建数据库 06 | 最终篇-通过AOP自动连接数据库-完成日志业 ...

  8. 10步完成Abp(.net core)+Vue的Demo?

    1.去abp官网生成项目,选择.net core1.x版本  2.Nuget还原包,需装dotnet core1.1等. 3.新增一个entity,并加入到上下文中 4.然后cmd命令行工具切换到项目 ...

  9. .Net Core+Vue.js模块化前后端分离快速开发框架NetModular更新日志(2019-12-08)

    源码 GitHub:https://github.com/iamoldli/NetModular 码云:https://gitee.com/laoli/NetModular 欢迎star~ 文档 ht ...

随机推荐

  1. 二次函数,为什么a>0就可以知道开口向上.

    最近自考. 学习高等数学. 学习高等数学过程中发现高中数学不会,,于是乎开始补高中数学. 学习高中数学过程中又发现初中数学有的不会,,于是乎开始补初中数学.. 可怕(→_→). 今天遇到一个二次函数, ...

  2. 构建gitlab+Jenkins+harbor+kubernetes的DevOps持续集成持续部署环境

    构建gitlab+Jenkins+harbor+kubernetes的DevOps持续集成持续部署环境 整个环境的结构图. 一.准备工作 gitlab和harbor我是安装在kubernetes集群外 ...

  3. Hyper-V 下linux虚拟机静态IP上网配置的两种方式(2)

    工作需要,搭建linux环境,网上搜了两种Hyper-V配置linux静态IP及上网的方式,记录一下,方便查阅,如下设置网络共享方式: win10下使用hyper-v在本机安装linux虚拟机后,网络 ...

  4. Flannel的VXLAN模式工作原理

    跨主机通信的一个解决方案是Flannel,由CoreOS推出,最早支持的是UDP模式,但是因为性能太差被淘汰了, 过时的UDP模式 相比两台宿主机直接通信,多出了flanneld的处理过程,发出IP包 ...

  5. mac专业视频剪辑软件 Final Cut Pro 10.4.6破解版

    Final Cut Pro简称FCP,它是 Mac平台上最好的视频剪辑软件,可用来视频剪辑.后期特效等.可编辑从标清到4K的各种分辨率视频,ColorSync管理的色彩流水线则可保证全片色彩的一致性. ...

  6. python学习(索引/切片)

    一.索引 1.索引值从左到右-->从0开始,索引值从右到左-->从-1开始 取值格式var[index] >>> name = "xinfangshuo&quo ...

  7. vc++源码免杀特殊技巧

    一.Debug 和 Release 编译方式的区别: Debug 通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序.Release 称为发布版本,它往往是进行了各种优化,使得程序 ...

  8. 【Labview入门】子VI的调用

    labview版本:Labview2015 Labview里面也可以向C语言等变成语言一样调用子程序,本文带你一步一步实现子VI的创建与调用. 第一步 写好程序 首先我们写个简单的加法程序: 我们的目 ...

  9. WPF使用border画框

    以前的界面中使用的框大都是由美工做好的,但是这样就遇到几个问题: 框只是换一个颜色,就需要多做出一张图,资源包中也要多一个图片资源: 文字的数量会改变,用一张固定的图进行拉伸,边角处会变得越来越不尽如 ...

  10. MS08-067 远程执行代码 漏洞复现

    漏洞编号:MS08-067 披露日期: 2008/10/22 受影响的操作系统:Windows 2000;XP;Server 2003;Server 2008;   目标系统 Microsoft(R) ...