首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ JavaScript / 文章详情

父组件使用callback向子组件传值,解决子组件获取不到值的问题

Sonder
2023-01-12
409字
1分钟
浏览 (1.6k)

父组件使用callback向子组件传值,解决子组件获取不到值的问题

父组件:father.vue

复制代码
<son @getUserId="getUserId"></son>
复制代码
methods: {
 getUserId(callback) {
   const uid = 1
   callback(uid)
 },
}

子组件:son.vue

复制代码
created(){
 this.$emit("getUserId",userId=>{
   this.userId = userId;
   console.log(`this.userId===>`, this.userId) // 1
 })
 console.log(`this.userId===>1111`, this.userId) // 1
},
下一篇 / PHP_thinkphp5上传多张图片

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)