用axios发布多维关联数组将为空

时间:2020-07-02 11:26:09

标签: vue.js axios

我试图在vue环境中发布多维关联数组,但它为空

convertedtext=[[key1:value1,key2:value2],[key1:value1,key2:value2],[key1:value1,key2:value2],[key1:value1,key2:value2]]

const res = await 
        this.$axios.$post("path",convertedtext
        ,{
            headers:{Authorization:`${token}`},
        })
        .then( () => {
        });

在控制台中查看请求内容为空

[[], [], [], []]
0: []
1: []
2: []
3: []

1 个答案:

答案 0 :(得分:1)

这里有两个选项:

a)将数组转换为字符串:

convertedtext=JSON.stringify([{key1:value1,key2:value2},{key1:value1,key2:value2},{key1:value1,key2:value2},{key1:value1,key2:value2}])

b)使用FormData()

   let FormData = new FormData();
   FormData.append('key',value)

    
        this.$axios.$post("path", FormData
        ,{
            headers:{Authorization:`${token}`},
        })
        .then( () => {
        });