子组件拿到父组件id
时间: 2023-09-01 09:10:04 浏览: 89
子组件向父组件传值.html
要子组件拿到父组件的id,可以在父组件中给子组件添加ref属性,并指定一个唯一的名称,比如"spu"。这样,在父组件中就可以通过this.$refs.spu来获取子组件的实例。通过子组件的实例,可以获取到父组件的id。具体代码如下所示:
```
<SpuForm v-show="scene==1" @changeScene="changeScene" ref="spu"></SpuForm>
```
在父组件中,可以通过this.$refs.spu来访问子组件的数据和方法,其中包括父组件的id。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [vue中父组件如何拿到并调用子组件的方法——通过ref](https://blog.csdn.net/wyhvivi/article/details/128290319)[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_2"}}] [.reference_item style="max-width: 50%"]
- *3* [通过组件ID修改组件内容.zip](https://download.csdn.net/download/qq1185907650/12602017)[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_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文