const wordSubmit = () => { // 获取选择好的信息 const selectedWordInfo = { name: timeStampName.value, // 名称 text_introduce: inputText.value, // 文字内容 isdraft: 0, // 类型 digitalapparel: selectClothingImageId.value, // 服装 digitalman: humanClothesList.value.id, // 主播 diaitalmain: info.id, // 数字人 voice: audioSelectId.value, // 语音 background: selectBackgroundImageId.value // 背景 } console.log(selectedWordInfo); saveWordSetName.value = false } export const selectedInfo = () => { return http({ url: '/digitalwork', method: 'post', headers: { 'Authorization': localStorage.getItem('token') } }) } 如何将获取到的数组 selectedWordInfo,通过axios提交到postman后台中
时间: 2024-04-23 17:25:44 浏览: 111
Vue.js获取被选择的option的value和text值方法
可以使用axios库发送POST请求将selectedWordInfo数组提交到后台中。代码如下:
```javascript
import axios from 'axios';
const wordSubmit = () => {
const selectedWordInfo = {
name: timeStampName.value,
text_introduce: inputText.value,
isdraft: 0,
digitalapparel: selectClothingImageId.value,
digitalman: humanClothesList.value.id,
diaitalmain: info.id,
voice: audioSelectId.value,
background: selectBackgroundImageId.value
};
axios({
method: 'post',
url: 'http://your-api-url.com/digitalwork',
data: selectedWordInfo,
headers: {
'Authorization': localStorage.getItem('token')
}
}).then(response => {
console.log(response);
saveWordSetName.value = false;
}).catch(error => {
console.log(error);
});
}
export const selectedInfo = () => {
return http({
url: '/digitalwork',
method: 'post',
headers: {
'Authorization': localStorage.getItem('token')
}
});
}
```
注意替换`'http://your-api-url.com/digitalwork'`为实际的后台API地址。同时,为了确保请求被授权,我们在请求头中添加了`Authorization`字段,并将其值设置为存储在本地的token。
阅读全文