Vuejs templates als asp.net partialviews, good practice?

I use Vue.js on a website and add templates in html code and js-Code in one js file. Therefore, I do not want to use the * .vue ↔ Vuefy / Browserfy method, but later I will link and reduce my js files.

As I should use Asp.Net MVC, I could use a split of one Html file in the view and insert vue-div elements hierarchically structured using @ Render.Partial (...). That way, I could do a clean split and use the same system as the * .vue files.

Would this be good practice?

Do you think it would be better to write html and a new Vue ({}) in each partial .cshtml or just write html code there and put javascript in (a) js file (s).

The js code in script-tags cannot be linked, and I don't like this much inline code, but it would mix components code well.

Using several js files, I could store them in the views folder next to their partial partners and link them together with the VSS extender and Minifier. enter image description here

Are these thoughts helpful or is there a good approach to using vuejs patterns in asp.net?

EDIT: I used some partial views with a specific Preifx. They include built-in script tags that are very close to the .vue approach and are cool in small components, because all this is on the same page. The inline script is conditional with Razor, therefore only in the dev assembly it becomes visualized inline, for its production it is sent separately. To do this, I wrote a powershell script file and executed it as a pre-build event to exctract all the embedded code in the js file. This file comes bundled with other js files and is maintained for production. Therefore, I can use all the Razor functions in html / templates, and other pages of the project are just * .cshtml views. For single-spa sites, the approach mentioned by iknowitwasyoufredo sounds better.

+5
source share
1 answer

If you use vue.js to perform some simple js tasks instead of jquery, I think this is good. But if you want to have a one-page application, routing, two-way binding, etc., mixing asp.net mvc views with vue.js is not a good idea. In the end, you will encounter many problems.

This is an architectural solution, but you can implement api web services using dotnet and use these services from the node.js application (express, webpack, vue.js).

+1
source

Source: https://habr.com/ru/post/1258595/


All Articles