小编the*_*gie的帖子

了解 Svelte tick() 生命周期

我已经阅读了 Svelte 文档的一半,并且很难理解tick()生命周期。React 中有替代方案吗?

例如,在教程的这个示例中它实际上做了什么?

<script>
import { tick }  from 'svelte';
let text = `Select some text and hit the tab key to toggle uppercase`;

async function handleKeydown(event) {
    if (event.which !== 9) return;

    event.preventDefault();

    const { selectionStart, selectionEnd, value } = this;
    const selection = value.slice(selectionStart, selectionEnd);

    const replacement = /[a-z]/.test(selection)
        ? selection.toUpperCase()
        : selection.toLowerCase();

    text = (
        value.slice(0, selectionStart) +
        replacement +
        value.slice(selectionEnd)
    );

    await tick();
    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;
} …
Run Code Online (Sandbox Code Playgroud)

javascript svelte

11
推荐指数
3
解决办法
7494
查看次数

'npm add'和'npm install --save'之间的区别?

我通过网络搜索,仍然无法得到,如果有什么区别npm add <package>npm install --save <package>

谢谢。

javascript npm npm-install

9
推荐指数
2
解决办法
3230
查看次数

标签 统计

javascript ×2

npm ×1

npm-install ×1

svelte ×1