我已经阅读了 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) 我通过网络搜索,仍然无法得到,如果有什么区别npm add <package>和npm install --save <package>。
谢谢。