vue--props--Function类型传递参数(默认参数+自定义参数)

第一种方法(奇怪)

父组件:

<component   :handleSpan="handleSpan"  />

script:

handleSpan(defaultParams,definedParams){

    .....

}

子组件:

<table :span-method="handleSpan1"></table>

script:

props:{

    handleSpan:{

        type:Function,

        default: function(){  return [1,1]    }//默认做的事情

    }

}

methods:{

    handleSpan1(defaultParams){

        return this,handleSpan(defaultParams,definedParams)//这里自定义参数是在子组件中定义的  No.1

    }

}

第二种方法

父组件:

<component   :handleSpan="handleSpan($event,definedParams)"  />

script:

handleSpan(defaultParams,definedParams){

.....//definedParams是在父组件中定义的

}

子组件:

<table :span-method="handleSpan1"></table>

script:

methods:{

    handleSpan1(defaultParams){

        this.$emit('handleSpan',defaultParams) // No.2

    }

}

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