uniapp调用子组件方法
时间: 2023-11-03 09:18:26 浏览: 149
在Uniapp中,可以通过使用`ref`属性来调用子组件的方法。首先,在父组件的模板中引入子组件,并给子组件添加一个`ref`属性作为标识。例如:
```html
<template>
<view>
<pop ref="pop"></pop>
</view>
</template>
```
然后,在父组件的脚本中,通过`$refs`属性来访问子组件并调用其方法。例如:
```javascript
<script>
import pop from '@/components/pop-up/pop.vue'
export default {
components: {
pop
},
methods: {
callChildComponentMethod() {
this.$refs.pop.functionName()
}
}
}
</script>
```
其中,`functionName`是子组件中的方法名称,通过`$refs.pop`来访问子组件对象,并调用其方法即可。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [uniapp 中父组件调用子组件方法](https://blog.csdn.net/weixin_49175501/article/details/117334781)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [uniapp父组调用子组件中的方法](https://blog.csdn.net/Mybabyying/article/details/108991668)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文