gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 12:15:10 25 4
gpt4 key购买 nike

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

<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 forsimple operations. Putting too much logic in your templates can makethem 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. Youhave to look at it for a second before realizing that it displaysmessage in reverse. The problem is made worse when you want to includethe 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com