Vue.js学习---v-on指令
来源:互联网 发布:数据库管理安全 编辑:程序博客网 时间:2024/06/09 20:58
Vue中经常会用到v-on指令来绑定一个事件,那么它具体什么时候调用,什么时候使用呢?
父组件中使用了v-on:editItem="editObject"和v-on:removeItem="removeObject"两个监听,代码如下
<v-list-box:key="props.item.documentNo"slot="listBox"slot-scope="props":item="props.item":items="props.items":index="props.index"v-on:editItem="editObject"v-on:removeItem="removeObject">
父组件中有两个方法,名为editObject和removeObject,因为代码太长就不贴过来,大家可以随意写一点,供自己观察就行
子组件中代码:
<divclass="box-toolspull-right">
<buttontype="button"class="btnbtn-box-tool"data-widget="collapse"><iclass="fafa-plus"></i></button>
<buttontype="button"class="btnbtn-box-tool"@click.submit.prevent="edit"><iclass="fafa-pencil"></i></button>
<buttontype="button"class="btnbtn-box-tool"@click.submit.prevent="remove"><iclass="fafa-times"></i></button>
</div>
<script>
export default {
name:'VListBox',
props:['item', 'index', 'items'],
data () {
return {}
},
methods: {
add () {
this.$emit('addItem')
},
edit () {
//此事件仅仅供父组件VListPage使用
this.$parent.$emit('_editItem', this.item)
this.$emit('editItem', this.item)
},
remove (){
this.$emit('removeItem', this.item)
}
}
}
</script>
大家请看,我们子组件当执行了edit方法时,通过$emit('editItem', this.item) 这个方法去父组件中去寻找editItem这个方法,然后调用它,在父组件中editItem实现。
当然remove也是一样的。
- Vue.js学习---v-on指令
- vue.js学习笔记之v-bind,v-on
- Vue常用指令v-on:click
- 11-Vue指令之V-on
- Vue.js 指令学习
- Vue.js入门-内置指令v-text
- Vue.js入门-内置指令v-html
- vue.js之v-on与v-bind
- Vue.js学习笔记:在元素 和 template 中使用 v-if 指令
- vue学习02--处理用户输入(v-on/v-model/v-show/v-text/v-html)
- Vue- v-html指令
- vue--v-model指令
- VUE基本指令(v-model,v-html,v-text,v-bind,v-if,v-show,v-for,v-on:click,组件,过滤器)
- vue的v-on
- Vue.js——v-指令详解,component组件
- vue.js 中v-bind指令的使用
- Vue.js学习笔记:v-for循环
- vue.js:Namespace "v-on" is not bound
- JAVA Date 工具类 常用
- 马云演讲01
- 欢迎使用CSDN-markdown编辑器
- SAX2 driver class org.apache.xerces.parsers.SAXParser not found
- CSS Grid 网格布局
- Vue.js学习---v-on指令
- Android项目中集成React Native
- overlay2下docker的文件结构
- 性能测试相关概念
- Java使用ffmpeg和mencoder实现视频转码
- mtbatis多参数处理方案
- 欢迎使用CSDN-markdown编辑器
- 显著性检测研究思路和方法
- qt在MacO下布局显示错乱的问题