我正在学习 Svelte,我想知道为什么单击事件在此示例中不起作用。我收到一条错误消息:
类型错误:每个值未定义'
https://svelte.technology/repl?version=1.56.1&gist=798be31e79dfbf363a9f7e497557acfb
<p><input bind:value=search></p>
{{#each categories.filter(predicate) as category}}
<!-- the click event should work, right? -->
<button on:click='console.log(category)'>{{category}}</button>
{{/each}}
<script>
export default {
data() {
return {
search: '',
categories: [
'animal',
'vegetable',
'mineral'
]
}
},
computed: {
predicate: search => {
search = search.toLowerCase();
return word => word.startsWith(search);
}
}
};
</script>