svelte

Condition for svelte tag attributes

僤鯓⒐⒋嵵緔 提交于 2019-12-08 10:56:18
问题 How to add attribute inline, without needing to duplicate the anchor tag ? https://svelte.dev/repl/a4e072ca670b481cb5d0360d01d07f27?version=3.12.1 <ul> {#each menu as item} <li> <a {item.prefetch ? 'rel=prefetch' : ''} href="{item.link}"> {item.title} </a> </li> {/each} </ul> I have Error compiling component when: {item.prefetch ? 'rel=prefetch' : ''} Next code works, but not quite what I need: rel={item.prefetch ? 'prefetch' : ''} 回答1: Try using undefined e.g. rel={item.prefetch ? 'prefetch'

Sapper/Svelte: How do I add markdown files?

☆樱花仙子☆ 提交于 2019-12-08 06:41:14
问题 I am creating a blog using Sapper using the default sapper-template-rollup. In the blog folder, it does mention about generating data from markdown files. But I can't find how to do it? 回答1: You may find this repo helpful. I also have an open PR on the Sapper Template repo, first revising the old Markdown branch in Jan. 2019 and then adding Svelte 3 support in May 2019, but it is probably easier to look at and clone my repo on GitLab, plus it has more current dependency updates I have not

Passing on:click event into dynamically created <svelte:component/>

心不动则不痛 提交于 2019-12-08 04:37:33
问题 I basically need to be able to trigger something within one or more components (that are being dynamically added via svelte:component) when an icon/button within the parent component is clicked. e.g. I need to hook the parts denoted with ** below:- <script> let charts = [ ChartA, ChartB, ChartC ]; </script> {#each charts as chart, i} <div class="wrapper"> <div class="icon" on:click={**HowToPassClickEventToComponent**}></div> <div class="content"> <svelte:component this={charts[i]} {*

Sapper/Svelte: How do I add markdown files?

巧了我就是萌 提交于 2019-12-06 16:07:34
I am creating a blog using Sapper using the default sapper-template-rollup . In the blog folder, it does mention about generating data from markdown files. But I can't find how to do it? You may find this repo helpful. I also have an open PR on the Sapper Template repo, first revising the old Markdown branch in Jan. 2019 and then adding Svelte 3 support in May 2019, but it is probably easier to look at and clone my repo on GitLab , plus it has more current dependency updates I have not added to the PR yet. You might have more lick using MDsveX which is a Svelte Markdown processor, created by

now-cli deployment doesn't build package.json dependencies

自闭症网瘾萝莉.ら 提交于 2019-12-06 09:44:28
I'm trying to deploy a Sapper built application via @now-node . The task is basically to deploy a Polka server with dependencies and to serve static/ and client/ files statically. I have managed to include the files that Lambda requires via includeFiles but now I see in the logs that the builder ignores dependencies described in package.json. The exact message is Starting server on port 3000 Cannot find module 'sirv' Did you forget to add it to "dependencies" in `package.json`? But I see in the build log that dependencies are not collected. Both package.json and package-lock.json are present

Does Svelte facilitate dynamic CSS styling?

耗尽温柔 提交于 2019-12-05 06:58:05
In Svelte, how should classes be changed on elements depending upon component state? For instance, you may wish to apply a class to a button under certain conditions, as in the following example. <button class="{{class}}"> Right now, this can be achieved by creating a computed property which would return class names, or empty strings, under certain conditions. However, I am concerned over whether this might be polluting the computed properties namespace. For instance, if there were a status , it might be desired to both set a dynamic text, like statusMessage , and a class, like statusClass .

Is it possible to dynamically load a Svelte template at runtime?

纵饮孤独 提交于 2019-12-02 01:06:33
I have looked at the documentation for [<svelte:component>] ( here ), but that looks like I would have had to import all of the possible templates at compile time. Is it possible in Svelte to load any number of arbitrary templates from something like a fetch() call based on a user action? Then inject data into it? Would it be inefficient to use <slot> for something like this, if I plan on updating it after the initial load? It's technically possible to create a component from the source text — the REPL does it , for example — since the compiler doesn't care if it's running in Node or the

Do dynamic props exist in Svelte 3

柔情痞子 提交于 2019-12-01 13:36:51
When I iterate over a dynamic component like: <svelte:component collection={collection} uid={uid} this={upload_component} bind:action={restart}/> Is it possible to use a set of dynamic props for each component. Each component having it's own set of prop names and prop values. Solution example: <script> import Info from './Info.svelte'; const pkgs = [{ name: 'svelte', version: 3, speed: 'blazing', website: 'https://svelte.dev' }, ]; </script> <Info {...pkgs[0]}/> More in this Rich Harris answer here . Yes. You need spread props : <svelte:component this={upload_component} bind:action={restart} {