vue关于父组件调用子组件的方法
2017-07-03 16:09
1036 查看
用$ref调用
直接代码:
父组件
直接代码:
子组件: <template> <div> </div> </template> <script> export default { data(){ return { num:'123' } }, computed: { }, components: { 'children': children }, methods:{ childMethod() { alert('childMethod do...') } }, created(){ } } </script>
父组件
父组件: 在子组件中加上ref即可通过this.$refs.ref.method调用 <template> <div @click="parentMethod"> <children ref="c1"></children> </div> </template> <script> import children from 'components/children/children.vue' export default { data(){ return { } }, computed: { }, components: { 'children': children }, methods:{ parentMethod() { console.log(this.$refs.c1) //返回的是一个vue对象,所以可以直接调用其方法 this.$refs.c1.childMethod(); } }, created(){ } } </script>
相关文章推荐
- vue组件之间的通信以及如何在父组件中调用子组件的方法和属性
- Vue $emit $refs子父组件间方法的调用
- vue 父组件调用子组件方法及事件
- vue 2.0 父组件调用子组件中的方法
- vue 子组件调用父组件方法
- vue中子组件调用兄弟组件方法
- vue 使用ref 让父组件调用子组件的方法
- vue.js组件之间通讯--父组件调用子组件的一些方法,子组件暴露一些方法,让父组件调用
- vue 使用ref 让父组件调用子组件的方法
- vue.js中父组件调用子组件的内部方法示例
- Vue $emit $refs子父组件间方法的调用实例
- [转]关于Microsoft.Office.Interop组件接口的调用方法
- 关于ASP.NET中调用Excel组件不能结束进程的解决方法
- vue 父组件调用子组件方法解决方案
- Vue兄弟组件之间如何调用对方的方法
- vue之子组件调用父组件的方法
- vue,父组件调用子组件方法
- vue 父组件调用子组件方法
- vue 子组件调用父组件的方法
- vue组件之间的通信以及如何在父组件中调用子组件的方法和属性