svelte-3

Add onChange handler to input in svelte

只愿长相守 提交于 2020-08-10 19:26:46
问题 Im trying to add the asYouType function from libphonenumber-js to my svelte input using an onChange handler as I'm not sure how this can be done with 2 way binding. I have managed to implement this but it will only format the number onBlur instead of as the user types into the input as is expeccted behaviour as seen here libphonenumber-js How can I change my input so that it will format as the user types into it? <script> import { AsYouType } from "libphonenumber-js"; export let value = "";

Svelte application bug: converting string to boolean in the view fails

廉价感情. 提交于 2020-07-22 05:42:07
问题 In a Svelte app, I have this array of countries: let countries = [ { name:"Alegeria", status: "1" }, { name:"Bulgaria", status :"0" } ] Note the status property is a string. I iterate the array this way: {#if countries.length > 0} <table class="table"> <thead> <tr> <th>Country</th> <th class="text-right">Status</th> </tr> </thead> <tbody> {#each countries as c} <tr> <td>{c.name}</td> <td class="text-right"><Switch bind:checked={Boolean(Number(c.status))} /></td> </tr> {/each} </tbody> </table

Svelte todo app bug: new todos id property is never greater than 2

﹥>﹥吖頭↗ 提交于 2020-07-10 10:27:54
问题 I am working on a small ToDo application in Svelte for learning purposes (Im new to Svelte). I have this code for adding a new todo: <script> import { onMount } from "svelte"; let todos = []; onMount(async function() { todos.reverse(); }); function addTodo() { //Empty todo object let newTodo = {}; //Set new todo object's properties (id, title, completed) if (todos.length == 0) { newTodo.id = 1; } else { newTodo.id = todos[todos.length - 1].id + 1; } newTodo.title = document.querySelector('

Svelte way for obtaining props values -in parent component and passing to a child component - after clicking on button

痞子三分冷 提交于 2020-06-29 04:34:14
问题 I'm learning svelte and sapper. I already have everything working correctly in my test app in one component but it is not optimal to build the whole app in one component. So my question here is about the svelte way of doing things. Keep this in mind while reading my question. It's a typical shopping app, page with products, button to add the product to the shopping cart and display the shopping cart and checkout button to finalize the user's purchase with the payment. My issue is about props

Svelte 3, async onMount or a valid alternative?

安稳与你 提交于 2020-06-14 15:33:54
问题 What I need is to use async-await in Svelte onMount() . Or maybe you can suggest me what is wrong and what I can use alternatively. To Reproduce go here: https://svelte.dev/repl/000ae69c0fe14d9483678d4ace874726?version=3.23.0 open the console click on the button you should see messages: "Mounting..." and "A lot of background work..." if you click again the destroy message is not written WHY? Did onMount() recognizes the async function promise? Should it? I need that async behavior because I