diff --git a/21-Vue基础/01-01.Vue的系统指令.md b/21-Vue基础/01-01.Vue的系统指令.md index 7d0e537..5d7ef04 100644 --- a/21-Vue基础/01-01.Vue的系统指令.md +++ b/21-Vue基础/01-01.Vue的系统指令.md @@ -18,6 +18,13 @@ - v-on +- 举例:文字滚动显示(跑马灯效果) + +- v-on的事件修饰符 + + + + ## Vue初体验 新建一个空的项目,引入vue.js文件。写如下代码: @@ -457,102 +464,6 @@ v-on 提供了click 事件,也提供了一些其他的事件。 - .... -### v-on的事件修饰符 - -`v-on` 提供了很多事件修饰符来辅助实现一些功能。事件修饰符有如下: - -- `.stop` 阻止冒泡。本质是调用 event.stopPropagation()。 - -- `.prevent` 阻止默认事件。本质是调用 event.preventDefault()。 - -- `.capture` 添加事件监听器时,使用 capture 模式。 - -- `.self` 只有当事件是从侦听器绑定的元素本身触发时,才触发回调。 - -- ``.{keyCode | keyAlias}` 只当事件是从侦听器绑定的元素本身触发时,才触发回调。 - -- ``.native` 监听组件根元素的原生事件。 - -写法示范: - -```html - - - - - - - - - - - - - - - - -
- - - -``` - - -**举例**:(`.prevent`的用法举例) - -现在有一个form表单: - -```html - -``` - - -我们知道,上面这个表单因为`type="submit"`,因此它是一个提交按钮,点击按钮后,这个表单就会被提交到form标签的action属性中指定的那个页面中去。这是表单的默认行为。 - -现在,我们可以用`.prevent`来阻止这种默认行为。修改为:点击按钮后,不提交到服务器,而是执行我们自己想要的事件(在submit方法中另行定义)。如下: - -```html - - - - - -