element-ui组件自带函数,参数传递

858 阅读1分钟

第一种

使用$event传递原有参数,往后传递你需要接受的参数

<el-button @click="click($event,'参数1')">按钮</el-button>
methods:{
    click(event,val){
        console.log(event,val)// 事件 参数1
    }
}

第二种

使用函数的形式进行参数传递 例:在使用文件上传的功能时,使用http-request函数时,我想进行参数传递,发现第一种方式行不通,使用函数的形式传参成功

<el-upload
    action="#"
    :on-remove="handleRemove"
    :before-remove="beforeRemove"
    :headers="headers"
    :http-request="(val)=>uploadImage(val,'参数1')"
    :before-upload="beforeImageUpload"
    multiple
    :limit="1"
    :on-exceed="handleExceed"
    :file-list="fileList"
>
<el-button size="small" type="primary" icon="el-icon-upload el-icon--right">点击上传</el-button>
<div slot="tip" class="el-upload__tip">最多可上传1张图片</div>
</el-upload>
mthods:{
    uploadImage(file,val){
        console.log(file,val) // file '参数1'
    }
}