首先在ts文件里接收一个参数 data
,类型为对象。该函数通过调用 post
函数向指定的路径接口 发送数据
export function calculateScore(data: object) {return post('写你的接口', data)
}//以上为举例,calculateScore等会会在vue页面去调用
然后我这里做处理的效果是个按钮
<ElButtontype="primary"@click="calculate()":icon="FolderAdd">计算分数</ElButton>
import {calculateScore} from "@写你calculateScore方法的文件夹路径";
async function calculate(){const res = await calculateScore({ids: ids.value.join(',')//我这里做处理的是个字符串,数组的话就把.join(',')去掉});if(res.code == 0){Message.success("计算成功!");}
}