.net core + vue 新手入門 ...
node.js下載地址 https://nodejs.org/en/download/ 安裝完成後 找到 Node.js command prompt 打開即為node的命令視窗 執行命令 npm install -g @vue/cli 查看vue版本 vue --version 創建一個新項目 vue create hello-world 運行項目 npm run serve 打包項目 npm run build 打包之後得到dist文件夾 可以將打包的發佈到IIS 參考 https://www.jianshu.com/p/7cc266438f09
新建net core項目 nuget 安裝 Microsoft.AspNetCore.SpaServices 2.11 VueCliMiddleware 2.11 把 hello-world項目複製到core項目根目錄 public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "hello-world/dist"; }); } app.UseSpa(spa => { spa.Options.SourcePath = "hello-world"; if (env.IsDevelopment()) { spa.UseVueCli(npmScript: "serve", port: 8080); // optional port } });
直接運行項目即可 訪問 http://localhost:8080/ 就是你的core項目啦