Majeed
315
8
Vue

Vuejs Avoid mutating a prop directly Warning

Posted 6 months ago by Majeed

this my props value.

<template>
      <!-- Modal -->
 <transition name="modal">
 <div class="modal modal-mask" style="display: block">
  <div class="modal-dialog" 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>
          {{roles}}
         <div class="form-group">
          <label>Name</label>
          <input name="name" class="form-control"/>
         </div>
         <div class="form-group">
          <label>E-mail</label>
          <input name="email" class="form-control"/>
         </div>
         <div class="form-group">
          <label>Role</label>
          <select multiple v-model="mutableRoles">
             <option v-for="role in mutableRoles">{{role.name}}</option>
           </select>
         </div>
          <div class="form-group">
          <label>Permissions</label>
          <select multiple class="form-control">
           <option>ABC</option> 
          </select>
         </div>
        
        </form>
      </div>
      
      <div class="modal-footer">
       <button type="button" class="btn btn-primary">Save</button>
       <button type="button" class="btn btn-danger" @click="close">Close</button>
      </div>
    </div>
  </div>
</div>
</transition> 
</template>
<script>
export default {
 

     props:{
       modalTitle:{
         type:String,
         required:true,
       },
       user:{
         type:[Array,Object],
         required:true,
       },
       roles:{
         type:[Array,Object],
         required:true,
       },
       permit:{
         type:[Array,Object],
         required:true,
       }
     },
    data(){
      return{
        mutableRoles: this.roles
      }
    },
   
    methods: {
        close:function(){
            this.$emit('closeModal');
        },
        
    },
}
</script>

I want to show this props value in dropdownlist this way. but it's show Avoid mutating a prop directly warn . what I've done wrong ?

Please sign in or create an account to participate in this conversation.