.Net Core Vue Qucik Start

.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:

.Net Core Vue Qucik Start_第1张图片

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

.Net Core Vue Qucik Start_第2张图片

2. Change Reactjs template to Vuejs template

  • Remove ClientApp folder:

.Net Core Vue Qucik Start_第3张图片

.Net Core Vue Qucik Start_第4张图片

  • Create new vue template project in root folder:

.Net Core Vue Qucik Start_第5张图片

.Net Core Vue Qucik Start_第6张图片

  • 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

  
    netcoreapp3.0
    true
    Latest
    false
    
    admin\
    $(DefaultItemExcludes);$(SpaRoot)node_modules\**
  
  • Add VueCliMiddleware package from nuget:

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

.Net Core Vue Qucik Start_第7张图片

  • 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

    
      
      
      
        %(DistFiles.Identity)
        PreserveNewest
        true
      
    
  • Run to test

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

.Net Core Vue Qucik Start_第8张图片

3. Case will be in the end

  • Install axios plugin:

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

.Net Core Vue Qucik Start_第9张图片

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

.Net Core Vue Qucik Start_第10张图片

  • add WeatherForecast.vue in views folder:






  • 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:

.Net Core Vue Qucik Start_第11张图片

Enjoy it!

你可能感兴趣的:(.Net Core Vue Qucik Start)