[SOLVED] Why is mixing Razor Pages and VueJs a bad thing?


I’m trying to set up a .NET core project using Razor Pages and include vueJs inside the razor page for all my logic.

Something like this:

    ViewData["Title"] = "VueJs With Razor";

<div id="app">
   <span>{{ message }}</span>

     new Vue({
        el: '#app',
        data: {
          message : 'Hello vue.js'

I have read that mixing Vue and Razor pages is a bad practice, and one should use Razor OR Vue.

Why is this?


You can do this. Sometimes you’re obliged to do it, if, like us, you’re migrating an existing code base and you can’t convert everything at once. And as Ron C says, it works well.

If you’re starting a new project, you have the luxury of choosing. Reasons for favouring an SPA and no Razor would be…

  • Reactivity. SPA apps generally feel (much) more reactive. Initial renders are often served from cache, before the data arrives. On first load, all resources arrive in a bundle, in one request-response. There’s no, or much less, request chaining.

  • Workflow. Webpack, bundling and hot reloads are great. You get production builds, with minification, compilation of Vue render functions, elimination of 404 style errors, js syntax errors are trapped. The cycle from introducing an error to discovering it is greatly reduced for many errors.

  • SPA universe. Routing, Vuex, this really is the way of the future.

  • Purity. Razor and Vue do similar things at the end of the day. If you mix them, you may have a hard time keeping your head straight.

Answered By – bbsimonbb

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *