我正在为 svelte 构建拖放组件,并想添加动画。我已经改编了另一个组件的代码,但我无法让它工作,你能帮我查明问题出在哪里吗?我不明白我得到的错误。这里正在工作 REPL
https://svelte.dev/repl/acc2c90db2054d89b210f23c026c525e?version=3.16.7
粘贴时显示错误:
in:receive={{ key: index }}
out:send={{ key: index }}
animate:flip={{ duration: 300 }}
Run Code Online (Sandbox Code Playgroud)
进入 REPL 组件的第 130 行
我收到以下错误消息:“使用 animate 指令的元素必须是每个键控块的直接子元素 (132:8)”
我试图删除“包裹”div 以将动画作为 #each 的“直接子级”移动,但它没有帮助
{#if list && list.length}
<div class="cont">
{#each list as item, index}
<div class="wrap">
<div
data-index={index}
id={index}
on:dragstart={() => { return false }}
on:touchstart={handleMousedown}
on:touchmove={handleMousemove}
on:touchend={handleMouseup}
on:mousedown={handleMousedown}
on:mousemove={handleMousemove}
on:mouseover={HandleMouseover}
in:receive={{ key: index }}
out:send={{ key: index }}
animate:flip={{ duration: 300 }}
class="tobedragged {((index == movingIndex) && moving) ? 'ghost' : …Run Code Online (Sandbox Code Playgroud) 你好:)
I'm trying to register an user and after success, setContext to newly registered user and then navigate to home. Server properly responds and registers user, but when setContext is called i get the following error: "index.mjs:552 Uncaught (in promise) Error: Function called outside component initialization"
<script>
import { setContext } from 'svelte'
async function handleRegistration(e) {
let user = {
firstname: e.target.firstname.value,
lastname: e.target.lastname.value,
}
fetch('http://localhost:3001/api/auth/register', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify(user)
})
.then(res => res.json())
.then(res => …Run Code Online (Sandbox Code Playgroud)