Home>Article>Web Front-end> What are modifiers in Vue? Summary of common modifiers
This article will give you a brief understanding of the modifiers inVue, and summarize some common modifiers and writing methods. I hope it will be helpful to everyone.

InVue, modifiers handle many ## The details of #DOMevents mean that we no longer need to spend a lot of time dealing with these troublesome things, but can have more energy to focus on the logical processing of the program. [Related recommendations:vuejs video tutorial] The modifiers in
vueare divided into the following five types:
inputtag , the most commonly used command isv-model
v-modelwill be executed every timeinputUpdate data after the event. You can add thelazymodifier to instead update the data after eachchangeevent:
{{value}}
.trimmodifier afterv-model:
.numbermodifier afterv-modelManagement input:
event.stopPropagationmethod. Clicking the event will stop delivery
//只输出1
event.preventDefaultmethod. Submitting the event will no longer reload the page
...
When using modifiers, you need to pay attention to the calling order, because the related codes are generated in the same order. So using@click.prevent.self
will prevent the default behaviorof all click events for theelement and its child elements, while@click.self.preventwill only Default behavior to prevent click events on the element itself.
capturecapture mode. For example, events pointing to internal elements are processed externally before being processed by internal elements. Make the event trigger from the top level containing this element downwards
obj1// 输出结构: 1 2 4 3obj2obj3obj4
onscrollevent triggered will make our web page become stuck, so when we use this modifier, it is equivalent to giving theonscrollevent a.lazymodification symbol.
onScrollto complete, in case it containsevent.preventDefault()
...
.passiveModifiers are generally used in touch event listeners and can be used toimprove the scrolling performance of mobile devices.
Do not use.passive
and.preventat the same time, because.passivehas already indicated to the browser that youDon't wantto block the default behavior of events. If you do this,.preventwill be ignored and the browser will throw a warning.
让组件变成像html内置标签那样监听根元素的原生事件,否则组件上使用v-on只会监听自定义事件
使用.native修饰符来操作普通HTML标签是会令事件失效的
鼠标按钮修饰符针对的就是左键、右键、中键点击,有如下:
键盘修饰符是用来修饰键盘事件(onkeyup,onkeydown)的,有如下:
keyCode存在很多,但vue为我们提供了别名,分为以下两种:
// 只有按键为keyCode的时候才触发
v-bind修饰符主要是为属性进行操作,用来分别有如下:
能对props进行一个双向绑定
//父组件//子组件 this.$emit('update:myMessage',params);
以上这种方法相当于以下的简写
//父亲组件func(e){ this.bar = e; } //子组件js func2(){ this.$emit('update:myMessage',params); }
使用async需要注意以下两点:
sync的时候,子组件传递的事件名格式必须为update:value,其中value必须与子组件中props中声明的名称完全一致.sync修饰符的v-bind不能和表达式一起使用v-bind.sync用在一个字面量的对象上,例如v-bind.sync=”{ title: doc.title }”,是无法正常工作的设置自定义标签属性,避免暴露数据,防止污染HTML结构
将命名变为驼峰命名法,如将view-Box属性名转换为viewBox
根据每一个修饰符的功能,我们可以得到以下修饰符的应用场景:
The above is the detailed content of What are modifiers in Vue? Summary of common modifiers. For more information, please follow other related articles on the PHP Chinese website!