The whole magic of webapps is that users can interact with our code via various DOM events and Svelte is no exception in that regard.

In this quick lesson we're going to learn how to use DOM events in Svelte 3 as well as how to use event modifiers to alter DOM event behaviour (such as once and preventDefault)

Doc: https://v2.svelte.dev/guide#event-handler-modifiers

<script>
let name;
const sayHello = () => alert('Hello ' + name);
const handleInput = e => name = e.target.value;
</script> <h1>
Hello:
</h1>
<input type="text" on:change={handleInput} />
<button on:click|preventDefault|once={sayHello}>Say name</button>

[Svelte 3] Use DOM events and event modifiers in Svelte 3的更多相关文章

  1. dom事件与event对象总结

    1 事件:就是文档或浏览器窗口中发生的一些特定的交互瞬间.    tips:js和xhtml的交互是通过当用户或浏览器操作网页时发生的事件来处理的. 1.1 事件流:即事件的顺序.        事件 ...

  2. Html页面Dom对象之Event

    HTML DOM Event 对象 实例 哪个鼠标按钮被点击? 光标的坐标是? 被按的按键的 unicode 是? 相对于屏幕,光标的坐标是? shift 键被按了吗? 哪个元素被点击了? 哪个事件类 ...

  3. [Svelte 3] Render HTML directly into a component in Svelte 3

    Disclaimer: please use this feature carefully. <script> let stringToRender = "<h1>H ...

  4. What are Scopes?

    scope is an object that refers to the application model. It is an execution context for expressions. ...

  5. Scope Directive

    ---------------------------Scope-------------------------------- https://docs.angularjs.org/guide/sc ...

  6. phantomjs 中文文档

    phantomjs 中文文档 转载 入门教程:转载 http://www.cnblogs.com/front-Thinking/p/4321720.html 1.介绍 简介   PhantomJS是一 ...

  7. Angular之 Scope和 Directive

    ---------------------------Scope-------------------------------- https://docs.angularjs.org/guide/sc ...

  8. 武者Vue

    1 - Introduction 2 - The Vue Instance 3 - Data & Methods 4 - Data Binding 5 - Events 6 - Event M ...

  9. Angular4.x Event (DOM事件和自定义事件)

    Angular组件和DOM元素通过事件与外部进行通信,两者中的事件绑定语法是相同的-(eventName)="expression": <button (click)=&qu ...

随机推荐

  1. 网站页面顶部出现空白行&#65279字符的原因以及完美解决办法

    转自个人博客:https://www.hurbai.com 有时候网页头部会出现一个空白行,查看源码发现body开头初有一个非法字符 // 如果是Windows系统,修改为:$WIN = 1; $W ...

  2. 利用Python进行数据分析_Numpy_基础_1

    ndarray:多维数组 ndarray 每个数组元素必须是相同类型,每个数组都有shape和dtype对象. shape 表示数组大小 dtype 表示数组数据类型 array 如何创建一个数组? ...

  3. Python爬虫—requests库get和post方法使用

    目录 Python爬虫-requests库get和post方法使用 1. 安装requests库 2.requests.get()方法使用 3.requests.post()方法使用-构造formda ...

  4. oracle多表关联删除的两种方法

    oracle多表关联删除的两种方法 第一种使用exists方法 delete from tableA where exits ( select 1 from tableB Where tableA.i ...

  5. extra bytes at beginning or within zipfile

    主要用文本文档打开看看是否带有#!/bin/bash 修改pom文件<executable>false</executable>

  6. hdu 6077多校签到

    #include <iostream> #include <cstdio> using namespace std; ][]; int f(int pos) { ; ;i< ...

  7. BFS以及hash表判重的应用~

    主要还是讲下hash判重的问题吧 这道题目用的是除法求余散列方式 前几天看了下算法导论 由于我们用的是线性再寻址的方式来解决冲突问题 所以hash表的大小(余数的范围)要包含我们要求的范围 对mod的 ...

  8. core路由设置

    全局路由设置 app.UseMvc(routes => { routes.MapRoute( name: "areas", template: "{area:exi ...

  9. C++string类字符串学习

    1.逆转字符串 第一种,使用algorithm中reverse函数. #include <algorithm> #include <string> #include <i ...

  10. [NOIP10.4模拟赛]3.z题解--思维

    题目链接: 咕咕 闲扯: 哈哈这道T3考场上又敲了5个namespace,300+行,有了前车之鉴还对拍过,本以为子任务分稳了 结果只有30分哈哈,明明用极限数据对拍过不知怎么回事最后数据又是读不全, ...