【发布时间】:2021-06-15 07:53:16
【问题描述】:
我是 Svelte 的新手,正在使用绑定。
这是我的代码:
test.svelte
<script>
let a = 1000000;
let b = "ABCDeFgH";
</script>
A: <input bind:value={a} />
<br><br>
B: <input bind:value={b} />
<br>
<!-- works only on first run -->
<p>Formatted <strong>a</strong> is {a.toLocaleString("en-US")} </p>
<!-- works on update -->
<p>Formatted <strong>b</strong> is {b.toLowerCase()}</p>
a 上的 toLocaleString() 方法适用于第一次加载,但在运行时使用输入框更新数字时不会格式化输出(带逗号)。
然而,toLowerCase() 似乎工作正常,即使在运行时更新到 b。
我在这里错过了什么?
【问题讨论】:
标签: svelte-3