2

I am trying to set the value of a hidden input with a value of id so that when I submit my form, I have the id. I know that this value is being passed using a param as follows:

  <td><router-link :to="{ name: 'editclient', params: { id: client.id }}">Edit</router-link></td>

Then in my EditClient component I have the following hidden input:

 <input type="hidden" value="{{this.$route.params.id}}" v-model="id">

The issue is that this won't compile, is there another way to do this?

I can see that the value of my id is set to 1 which is what it should be in this case: enter image description here

However the issue is that I can't bind this to my hidden input.

Any help is appreciated, thanks

2 Answers 2

4

In this case I would probably just use v-model

<input type="hidden" v-model="id">

And then set id either in data or when the route changes.

data(){
    return {
        id: this.$route.params.id
        ...
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

odd, it still seems to say that value is null yet I can see it in $route.params.id : <input type="hidden" value="">
Well, what is 'id'.
1

Just for reference incase someone else hits this issue, I managed to solve this by using a computed attribute in my component:

  computed: {
            id () {
                return this.$route.params.id
            }
        },

Comments

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.