Home > Web Front-end > JS Tutorial > Svelte Counter I made to understand runes

Svelte Counter I made to understand runes

Susan Sarandon
Release: 2024-11-21 03:03:09
Original
1042 people have browsed it

The final result.
Svelte Counter I made to understand runes

This is the Svelte code I wrote to create a counter.

Link to code

<script>
  let number = $state(0);
  let currentValue = $derived(number);

  const addByOne = () => (number  = 1);
  const decreaseByOne = () => (number > 0 ? (number -= 1) : 0);
  const reset = () => (number = 0);
  const multiplyByTwo = () => (number *= 2);
</script>

<div>




          

            
        
Copy after login

The above is the detailed content of Svelte Counter I made to understand runes. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template