09月22日, 2014 1841次
vue nui-app通过ref特性调用子组件的方法
【1】子组件code:
<template> <div>{{msg}}</div> </template> <script> export default { data() { return { msg: '子组件' } }, methods: { changeMsg() { this.msg = 'xxx' } } } </script>
【2】父组件code:
<template> <div @click="parentMethod"> <children ref="children"></children> </div> </template> <script> import children from 'components/children.vue' export default { components: { children }, data() { return {} }, methods: { parentMethod() { this.$refs.children //返回一个对象 this.$refs.children.changeMsg() // 调用children的changeMsg方法 } } } </script>
暂无留言,赶快评论吧