Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Majeed's avatar

v-bind & v-model binding error in Vue.js

I've use v-bind and v-model in my form input field. but when i run npm run dev command it's show the: v-bind:value="user.name" conflicts with v-model on the same element because the latter already expands to a value binding internally error.

in v-bind i'm bind my props value and in v-model use a variable.

This is my Child Component.

<transition name="modal">
 <div class="modal modal-mask" style="display: block">
  <div class="modal-dialog modal-overflow" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">
          {{modalTitle}}
        </h4>
        <button type="button" class="close" aria-label="Close" @click="close">
        <span aria-hidden="true">&times;</span>
      </button>
      </div>
      
      <div class="modal-body">
        <form>
        
         <div class="form-group">
          <label>Name</label>
          <input name="name" class="form-control"  v-model="username"/>
         </div>
         <div class="form-group">
          <label>E-mail</label>
          <input name="email" class="form-control" v-bind:value="user.email"/>
         </div>
         <div class="form-group">
          <label>Role</label>
          {{userRoles}}
          <select multiple v-model="userRoles" class="form-control"  >
                {{datauser}}
               <option v-for="(role,index) in roles" v-bind:value="role.id">{{role.name}}</option>

           </select>
         </div>
          <div class="form-group">
          <label>Permissions</label>
          <select multiple class="form-control" v-model="mutablePermissions" >
           <option v-for="(permission,index) in permit"  v-bind:value="permission.id">{{permission.name}}</option> 
          </select>
         </div>
        
        </form>
      </div>
      
      <div class="modal-footer">
       <button type="button" class="btn btn-primary" @click="updateUser">Save</button>
       <button type="button" class="btn btn-danger" @click="close">Close</button>
      </div>
    </div>
  </div>
</div>
</transition> 
<!--end modal-->
</template>
<script>
export default {
  // props:[
  //   'modalTitle',
  //   'user',
  //   'roles'
  // ],

    props:{
      modalTitle:{
        type:String,
        required:true,
      },
      user:{
        type:[Array,Object],
        required:true,
      },
      mutableRoles:{
        type:[Array,Object],
        required:true,
      },
      roles:{
        type:[Array,Object],
        required:true,
      },
      permit:{
        type:[Array,Object],
        required:true,
      }
    },
    data(){
      return{
       
       mutablePermissions:[],
       userRoles:[],
       userPermissions:[],
       username:this.user.name,
       email:'',
       id:''
      }
    },
    created() {
     
    },
   
    methods: {
        close:function(){
            this.$emit('closeModal');
          
        },
        updateUser:function(){
          return this.username
        }
        
    },
    computed: {
        datauser:function(){
          this.userRoles=this.mutableRoles
        },
        
    },
    watch: {    
    },
    mounted() {
     
    },
}
</script>

pass props value from Parent component.

  <update-modal v-show="ismodalOn" @closeModal="shutModal" :modalTitle="title" :mutable-roles="userdata" :user="user" :roles="roles" :permit="permissions"/>

How can i solve this issue.

0 likes
15 replies
realrandyallen's avatar

You can't bind the value and use v-model on the same element, all you need is the v-model and set the data property to the passed in prop's value

<input name="name" class="form-control" v-model="username"/>

 props:{

      user:{
        type:[Array,Object],
        required:true,
      },

    },
    data(){
      return{

       username: this.user.name,
       email:'',
       id:''
      }
    },
realrandyallen's avatar

@MAJEED - What do you see in the console if you add this to mounted?:

    mounted() {
        console.log(this.user);
    },
Majeed's avatar

@REALRANDYALLEN - It's show a warning [Vue warn]: Error in mounted hook: "ReferenceError: user is not defined"

Majeed's avatar

no, my child component is a modal that's occur this problem

realrandyallen's avatar

@MAJEED - Your parent component is sending user to the child

<update-modal v-show="ismodalOn" @closeModal="shutModal" :modalTitle="title" :mutable-roles="userdata" :user="user" :roles="roles" :permit="permissions"/>

The question is, does the parent component even have user properly to send to the child?

Majeed's avatar

I Can access the value when i use v-model=user.name

realrandyallen's avatar
Level 44

@MAJEED - ah, I think the issue is you would need to move username down to a computed property since you're dealing with a child component

computed: {
    datauser:function(){
        this.userRoles=this.mutableRoles
    },
        
    username: function() {
        return this.user.name;
    }
},

And make sure to remove username from your data() property

Please or to participate in this conversation.