子组件向父组件传值的几种方式

Vue内置API

  1. 子组件
this.$emit('toTakeoutMethods', index)
  1. 父组件
<tabs @toTakeoutMethods="func"></tabs>
func(data){
                this.activeIndex = data
                console.log(data);
            }

Uni-app 内置API

  1. 子组件
uni.$emit('toFather', index)
  1. 父组件

要在onLoad() 中写

            uni.$on('toFather', res => {
                this.activeIndex = res
                console.log(res);
            })

this.$parent 方式

  1. 子组件
this.$parent.toFatherMethods(index)
  1. 父组件
toFatherMethods(index){
                this.activeIndex = index
                console.log(index);
            }

Vuex方式也可以传值

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。