Howto do something when an attribute changes in svelte
问题 Creating a web component using svelte, I need to run some code when an attribute of the component is changed. What I have come up with is the following pattern. <script> export let test = "default value"; $: { testIsChanged(test); } function testIsChanged(newValue) { console.log(newValue); } </script> The value of test is {test} Is this the way to do it? Or am I missing something? 回答1: That will indeed work, as you can see in this REPL 来源: https://stackoverflow.com/questions/57976936/howto-do