javascript - 如何在vue模板中按行分割内联JS表达式?

标签 javascript templates vue.js coding-style

在编写这段代码时,我遇到了这个问题:

<span
  class="deal-card__cost"
>{{ deal.total_cost | currency(
                        '₽',
                        0,
                        {
                          thousandsSeparator: ' ',
                          symbolOnLeft: false,
                          spaceBetweenAmountAndSymbol: true
                        }
                      ) | placeholder('- - -') }}</span>

并且无法解析。 Vue 模板中是否可以拆分 inine JS 表达式?如果是 - 怎么办?

最佳答案

From the guide :

In-template expressions are very convenient, but they are meant for simple operations. Putting too much logic in your templates can make them bloated and hard to maintain.

For example:

<div id="example"> 
  {{ message.split('').reverse().join('') }}
</div>

At this point, the template is no longer simple and declarative. You have to look at it for a second before realizing that it displays message in reverse. The problem is made worse when you want to include the reversed message in your template more than once.

That’s why for any complex logic, you should use a computed property.

关于javascript - 如何在vue模板中按行分割内联JS表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51223665/

相关文章:

javascript - jquery/ajax 提要解析器脚本在页面上不起作用

c++ - 通用工厂设计模式的实现

c++ - 图灵机 : But why use template metaprogramming?

javascript - vuejs 根据条件选择选项更改

javascript - Vue.js @keydown 获取按下的键

vue.js - Vue 3 - 使特定的类属性具有反应性

javascript - 在 React 中使用渐变 API 自定义下划线

c# - 计算百分比值在 javascript 和 c# 之间有所不同

空搜索结果上的 Javascript Algolia JS .clear Cache() 始终是 "search behind"

c++模板函数参数推导和函数解析