为什么混合Razor Pages和VueJs是一件坏事? [英] Why is mixing Razor Pages and VueJs a bad thing?

查看:511
本文介绍了为什么混合Razor Pages和VueJs是一件坏事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Razor Pages建立一个.NET核心项目,并在我的所有逻辑中将vueJ包含在razor页面中.

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

类似这样的东西:

@{
    ViewData["Title"] = "VueJs With Razor";
}
<h2>@ViewData["Title"].</h2>

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

<script>
     new Vue({
        el: '#app',
        data: {
          message : 'Hello vue.js'
        }
    })
</script>

我已经读过,混合使用Vue和Razor页面是一种不好的做法,应该使用Razor OR Vue.

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

这是为什么?

推荐答案

您可以执行此操作.有时候,如果像我们一样,您正在迁移现有的代码库,而又无法一次转换所有内容,则您有义务这样做.正如罗恩·C(Ron C)所说,它运作良好.

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.

如果您要开始一个新项目,则可以选择.选择SPA而没有Razor的原因将是...

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

  • 反应性. SPA应用程序通常感觉(非常)更活跃.初始渲染通常在数据到达之前从缓存中提供.第一次加载时,所有资源都以一个请求-响应的形式捆绑在一起.没有或几乎没有请求链接.

  • 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.

工作流程. Webpack,捆绑和热重装都很棒.您将获得生产版本,并进行精简,Vue渲染功能的编译,消除404样式错误,捕获js语法错误.对于许多错误,从引入错误到发现错误的周期大大缩短了.

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世界.路由,Vuex,这确实是未来的方式.

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

纯度. Razor和Vue在一天结束时会做类似的事情.如果混合使用它们,可能会很难保持直立.

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.

这篇关于为什么混合Razor Pages和VueJs是一件坏事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆