0

I have an HTML form, which used to have input values based on a Vue array like so:

// Vue Var
var postIDarr = [postID, postID, etc., etc.];
// HTML
<input v-for="(id, index) in postIDarr" type="hidden" name="postIDArr[]" :key="index" :value="id">

This worked fine for a while, but now I want to make the array an associative array, encoding both the postID and the userID for processing on the backend. The array in Vue has the structure as follows;

var postIDarr = {
    userID: postID,
};
// These are placeholders obviously

How would I be able to encode both of these values into the HTML form?

Wasn't entirely sure how to write this question without being repetitive, if you need any more information please let me know.

2

1 Answer 1

1

if you have an object like :

var postIDarr = {
    userID: postID,
}

and you want want render it using v-for by showing the key and value, so you could do it like :

 v-for="(id,key, index) in postIDarr" 

id refers to postID

key refers to userID

Sign up to request clarification or add additional context in comments.

2 Comments

and how would I attach both of these values into an array input?
what do you mean by attach?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.