Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vuejs templates als asp.net partialviews, good practice?

i'm using Vue.js in a Website and added the templates in the html Code and the js-Code in a single js-file. So i do not want to use the *.vue <-> Vuefy/Browserfy approach but bundle and minify my js-files later.

As i have to use Asp.Net MVC i could use split the single Html-file in a view and insert the vue-div-elements hierarchically structured with @Render.Partial(...). This way i could do a clean separation and use the same system like the *.vue files.

Would this be a good practice?

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

The js-code in script-tags could not be bundled and i don't like that much inline Code but it would a nice coupling of the components code.

By using multiple js-files i could store then in the views folder next to their partial partners and bundle them together with the VS Extension Bundler and Minifier. enter image description here

Are these thoughts usefull or is there still a good aproach for using vuejs templates in asp.net?

EDIT: I used to write some of the partial views with a specific Preifx. The include inline script tags, wich comes the .vue approach very close and is cool in small components because its all in one page. The inline script is conditional with Razor, so only in the dev build it gets rendered inline, for production it get's send separated. To do so I wrote a powershell script and execute it as pre-build event to exctract all the inline code into a js-file. This file get's bundled with the other js-files and is served minified for production. So i can use all the Razor features in the html/templates and other pages of the project are just *.cshtml views. For only-one-SPA-sites the approach mentioned by iknowitwasyoufredo sounds better.

like image 953
Reiner Avatar asked Oct 21 '16 09:10

Reiner


1 Answers

If you use vue.js to do some simple js tasks, instead of jquery I think it is good. But if you want to have a single page application, routing, two way binding etc. mixing asp.net mvc views with vue.js is not a good idea. Eventually, you will face many problems.

It's an architectural decision but you could implement web api services with dotnet, and use this services from a node.js application (express, webpack, vue.js).

like image 89
iknowitwasyoufredo Avatar answered Oct 01 '22 00:10

iknowitwasyoufredo