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

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

问题描述

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

像这样:

@{ViewData["Title"] = "VueJs with Razor";}<h2>@ViewData["Title"].</h2><div id="应用程序"><span>{{消息}}</span>

<脚本>新的 Vue({el: '#app',数据: {消息:'你好 vue.js'}})

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

这是为什么?

解决方案

您可以这样做.有时,如果您像我们一样迁移现有代码库并且无法一次转换所有内容,则您不得不这样做.正如 Ron C 所说,它运行良好.

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

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

  • 工作流程.Webpack、捆绑和热重载都很棒.你得到生产版本,缩小,编译 Vue 渲染函数,消除 404 样式错误,捕获 js 语法错误.对于许多错误,从引入错误到发现错误的周期大大缩短.

  • SPA 世界.路由,Vuex,这真的是未来的方式.

  • 纯洁.Razor 和 Vue 在一天结束时做类似的事情.如果将它们混合在一起,您可能很难保持头脑清醒.

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";
}
<h2>@ViewData["Title"].</h2>

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

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

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.

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

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