我还没有在svelte 3中找到这个特性。我希望它是这样的..
App.svelte
<Error>
<p>Can't connect to the server!</p>
</Error>`
Error.svelte
<div>{props.children}</div>
我想让App.svelte显示:
<div><p>Can't connect to the server!</p></div>
我只知道如何使用React的props.childre
所以我用svelte创建组件,并在其中添加自定义逻辑,
但是编译好了。
然后使用本机javascript使用编译后的版本,而不执行svelte的npm安装。
基本上,我希望我能做这样的事情:
function test(text) {
// for example let's add with native JS this component
document.body.innerHTML += `<MyCard myParameter="${text}">` // when calling myCard it will create also s
如何获取当前svelte文件的所有属性?
例如,这个Component1.svelte
<script>
let x = '';
let y = '';
let z = '';
onMount(function(){
console.log( what? );
// need to print x, y, and z which set by other code
// that using/importing this file
// without defining one by
我有这个登陆页面,我有一个表单和一个函数,需要在提交表单时触发。以下是功能:
async function sendWaitlistData() {
const name_input = document.getElementById("name") as HTMLInputElement;
const name_arr = name_input.value.split(" ");
var first_name = name_arr[0];
for (let i = 0; i < name_a
我有一个store.js文件,它的内容是:
import { writable } from 'svelte/store';
export const generateds = writable(0);
console.log("generateds", $generateds)
每次我尝试访问$generateds (在此文件内部或外部)时,我都会收到以下错误:
Uncaught ReferenceError: $generateds is not defined
at stores.js:4
at main.js:6
当我在一个新项目中使
是否可以创建组件并以编程方式将事件侦听器附加到组件上?
我知道,这对于使用<svelte:component/>的道具来说是很容易的,因为它可以通过{ ...props }进行传播。我想知道是否可以实现类似的东西来附加事件侦听器。
例如,在下面的示例中,我希望以编程方式将on:message附加到A,将on:count附加到B
<!-- App.svelte -->
<script>
import A from './A.svelte';
import B from './B.svelte';
let
每当"view.current“更改时,我都想重新复制"Body”(我的svelte组件),以便它呈现相应的.svelte视图/组件:
App.svelte
<script>
import Header from "./components/Header.svelte";
import Footer from "./components/Footer.svelte";
import Body from "./components/Body.svelte";
import Log