TypeError: $$invalidate(...) is not a function in Svelte
TypeError: $$invalidate(...) is not a function in Svelte
我有一个显示评论的轮播。单击按钮时,出现此错误:
TypeError: $$invalidate(...) is not a function
奇怪的是,一切正常,所以没有什么坏掉的。但我无法理解此错误的来源或原因。这是代码:
<script>
let showntestimonial = 1;
const testimonials = [ { // array of objects } ];
</script>
<section class="customer-testimonial">
<button
class="arrowbox"
on:click={() => (showntestimonial += 2)((showntestimonial = showntestimonial % 3))}>
<i class="far fa-chevron-left" />
</button>
<div class="textbox">
<p>
{@html testimonials[showntestimonial].text[$language]}
</p>
<h2>
{@html testimonials[showntestimonial].name}
</h2>
</div>
<button
class="arrowbox"
on:click={() => (showntestimonial++)((showntestimonial = showntestimonial % 3))}>
<i class="far fa-chevron-right" />
</button>
</section>
好吧,我仍然不知道问题的确切根源,但我能够通过使用 "normal" 函数语法而不是那种奇特的语法来修复它。所以修复错误的代码是这样的:
<button
class="arrowbox"
on:click={() => {
showntestimonial += 2;
showntestimonial = showntestimonial % 3;
}}>
<i class="far fa-chevron-left" />
</button>
这不是 Svelte 错误,而是您的代码中的错误。当你写这个...
(showntestimonial++)((showntestimonial = showntestimonial % 3))
...你说的是 'call showntestimonial++
with the argument (showntestimonial % 3)
'。但是 showntestimonial++
不是一个函数,它是一个数字——你不能调用它。
我有一个显示评论的轮播。单击按钮时,出现此错误:
TypeError: $$invalidate(...) is not a function
奇怪的是,一切正常,所以没有什么坏掉的。但我无法理解此错误的来源或原因。这是代码:
<script>
let showntestimonial = 1;
const testimonials = [ { // array of objects } ];
</script>
<section class="customer-testimonial">
<button
class="arrowbox"
on:click={() => (showntestimonial += 2)((showntestimonial = showntestimonial % 3))}>
<i class="far fa-chevron-left" />
</button>
<div class="textbox">
<p>
{@html testimonials[showntestimonial].text[$language]}
</p>
<h2>
{@html testimonials[showntestimonial].name}
</h2>
</div>
<button
class="arrowbox"
on:click={() => (showntestimonial++)((showntestimonial = showntestimonial % 3))}>
<i class="far fa-chevron-right" />
</button>
</section>
好吧,我仍然不知道问题的确切根源,但我能够通过使用 "normal" 函数语法而不是那种奇特的语法来修复它。所以修复错误的代码是这样的:
<button
class="arrowbox"
on:click={() => {
showntestimonial += 2;
showntestimonial = showntestimonial % 3;
}}>
<i class="far fa-chevron-left" />
</button>
这不是 Svelte 错误,而是您的代码中的错误。当你写这个...
(showntestimonial++)((showntestimonial = showntestimonial % 3))
...你说的是 'call showntestimonial++
with the argument (showntestimonial % 3)
'。但是 showntestimonial++
不是一个函数,它是一个数字——你不能调用它。