简体   繁体   English

我们如何将Vue JS与ASP.NET MVC和nuget包集成在一起

[英]How can we integrate Vue JS with ASP.NET MVC and nuget packages

How can we integrate Vue JS with MVC Project that is existing and using with Nuget Package. 我们如何将Vue JS与现有的并与Nuget Package一起使用的MVC Project进行集成。

Tried with below approach. 尝试使用以下方法。

<h3>VueJS 2 in ASP.NET MVC 5</h3>
<div id="aboutPage">
    { { message }}
</div>
<script>
    var aboutPage = new Vue({
        el: '#aboutPage',
        data: {
            message: 'Hello Vue! in About Page'
        }
    });
</script>

Question: 题:

  1. Is there need for any additional package like - webpack or gulp, we already have bundle config of MVC? 是否需要任何其他软件包-webpack或gulp,我们已经有了MVC的捆绑包配置?

2. How can we create separate files or design for each view like: 2.我们如何为每个视图创建单独的文件或设计,例如:

  1. To separate the service call (to call web api from client side) 分隔服务调用(从客户端调用Web API)

  2. separate out the template file. 分离出模板文件。

  3. methods or logic to write in JS. 用JS编写的方法或逻辑。

any example for MVC with VueJS like - controller, view,service, vue JS file is great.. 任何带有VueJS的MVC的示例-控制器,视图,服务,vue JS文件都很棒。

Thanks a lot ! 非常感谢 !

You can use vuejs buy adding it to your layout. 您可以使用vuejs购买将其添加到布局中。

 @Scripts.Render("~/node_modules/vue/dist/vue.min.js")

You need to install Nodejs on your machine to use NPM and ES6 features. 您需要在计算机上安装Nodejs才能使用NPM和ES6功能。 For integrate Vue.js in .NET MVC you need module bundler (webpack, gulp),can choose one of this options, the popular is webpack: 要将Vue.js集成到.NET MVC中,您需要模块捆绑器(webpack,gulp),可以选择以下选项之一,其中流行的是webpack:

1:(Gulp, Browserify), which has some limitations such as supporting only require syntax handling assets. 1:(Gulp,Browserify),它有一些限制,例如仅支持语法处理资产。 and the setup is kind of complicated. 而且设置有点复杂。

2:(Webpack), which has a lot of cool things you can do with it, Hot Reload. 2:(Webpack),您可以使用它进行很多有趣的操作,即热重装。 check this repo by using webpack, you config it to handle just js files and it will handle js files for build too , upon build each entry will be copied inside Scripts/bundle, also you need some loaders such ass (vue, scss, css and js) for webpack. 通过使用webpack 检查此仓库,您将其配置为仅处理js文件,它也将处理js文件进行构建,在构建时,每个条目都将复制到Scripts / bundle内,此外,您还需要一些加载程序,例如ss(vue,scss,css和js)用于webpack。 check this 检查这个

Webpack uses webpack-dev-server for development which is basically a node.js based server which serves assets (javascript, css etc) that our browsers can interpret. Webpack使用webpack-dev-server进行开发,该服务器基本上是基于node.js的服务器,用于提供浏览器可以解释的资产(javascript,css等)。 Usually these assets include some development friendly features like Hot Reload. 通常,这些资产包括一些对开发友好的功能,例如热重载。 These assets are not minified and are quite different from the ones generated when building for production. 这些资产没有缩小,并且与为生产而建造的资产完全不同。

devServer: {
proxy: {
    '*': {
        target: 'http://localhost:5001',
        changeOrigin: true
    }
}

}, },

webpack-dev-server has a feature which can proxy requests from one url to another. webpack-dev-server具有一项功能,可以将请求从一个URL代理到另一个。 In this case, every request from "webpack dev server " will be proxied to your "asp.mvc server". 在这种情况下,来自“ webpack开发服务器”的每个请求都将被代理到您的“ asp.mvc服务器”。 So, if we run our MVC app on http://localhost:5001 and run npm run dev , on port 8086 you should see the same output as from our MVC app. 因此,如果我们在http:// localhost:5001上运行我们的MVC应用程序,并在端口8086上运行npm run dev,您应该会看到与我们的MVC应用程序相同的输出。

Answers: 1: yes you have to setup Webpack or Gulp. 答案:1:是的,您必须设置Webpack或Gulp。 2. by using webpack you can all thing for file structuer that you want check this tree 2.通过使用webpack,您可以检查想要的文件结构的所有内容

-app -app
--libs --libs
----utils ---- utils的
----components - - 组件
---------commons ---------公地
---------....... ---------.......
-----pages -----页
---------..... ---------.....

check this articles 检查这篇文章
https://medium.com/corebuild-software/vue-js-and-net-mvc-b5cede228626 https://medium.com/corebuild-software/vue-js-and-net-mvc-b5cede228626
http://www.lambdatwist.com/dot-net-vuejs/ http://www.lambdatwist.com/dot-net-vuejs/

If you want to keep the .cshtml files and use MVC as a multipage application, you can take a look at this template as an example or starting point. 如果要保留.cshtml文件并将MVC用作多页应用程序,则可以以该模板为例或起点。 https://github.com/danijelh/aspnetcore-vue-typescript-template https://github.com/danijelh/aspnetcore-vue-typescript-template

You can create modules of pages which you want to enhance with Vue and import that bundle. 您可以创建要使用Vue增强的页面模块,然后导入该捆绑包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Dropzone.js 与 ASP.NET 核心 MVC 集成? - How to Integrate Dropzone.js with ASP.NET Core MVC? 将 Vue.js 集成到现有 ASP.NET MVC5 项目的最佳方式 - Best way to integrate Vue.js into existing ASP.NET MVC5 Project 我们可以将整个 model 传递给 javascript asp.net mvc - can we pass entire model to javascript asp.net mvc 如何在Ember.js应用程序中将ASP.NET Identity与ASP.NET Web API集成 - How to integrate ASP.NET Identity with ASP.NET Web API in Ember.js application 如何将 asp.net mvc 5 与最新的 Paypal checkout .net sdk v2 集成? - how to integrate asp.net mvc 5 with latest Paypal checkout .net sdk v2? 您如何序列化JS数组,以便Asp.net MVC可以将其绑定到ac#列表? - How do you serialize a JS array so Asp.net MVC can bind it to a c# list? 如何在ASP.Net MVC中使用Backbone.js? - How can I use Backbone.js with ASP.Net MVC? 如何将datetimepicker与ASP.NET本地化集成 - How to integrate datetimepicker with ASP.NET localisation Vue + Asp.Net MVC - 在 cshtml 属性中使用 vue mustache - Vue + Asp.Net MVC - Using vue mustache in cshtml attributes 如何使用JavaScript,React,Angular,Vue或ASP.NET MVC隐藏Kendo UI网格列 - How Can I Hide Kendo UI Grid Columns using JavaScript, React, Angular, Vue or ASP.NET MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM