title: Vue: props doesn't get assigned automatically; when assigned manually - Avoid mutating a prop directly - error
body: <p>I have two <code>vue</code> components: <code>GetAnimal.vue</code> and <code>DisplayAnimal.vue</code>. <code>GetAnimal.vue</code> send a JSON with animal data to <code>DisplayAnimal.vue</code> using router push. <code>DisplayAnimal.vue</code> displays that data. It works like this: I go to <code>/getanimal</code>, click a button that triggers the <code>getAnimal()</code> function which leads me to <code>/viewanimal</code> (via a router push):</p>
  
  <p><strong>GetAnimal.vue</strong>:</p>
  
  <pre><code>&lt;script&gt;
      import axios from 'axios';
  
      export default {
          data: function () {
              return {
                  name: 'defaultAnimal',
                  defaultanimal: {
                      name: 'Cat',
                      furColor: 'red',
                      population: '10000',
                      isExtinct: false,
                      isDomesticated: true
                  },
                  animal: String
              }
          },
          methods: {
              getAnimal: function () {
                  console.log("this.defaultanimal: " +
                      JSON.stringify(this.defaultanimal));
  
                  this.$router.push({
                       name: "viewanimal",
                      params: {
                           animal: this.defaultanimal
                       }
                   });
  
              },
  ...
  </code></pre>
  
  <p><strong>DisplayAnimal.vue</strong>:</p>
  
  <pre><code>&lt;template&gt;
      &lt;div&gt;
          &lt;h1&gt;Displaying animal:&lt;/h1&gt;
          &lt;p&gt;Animal name: {{animal.name}}}&lt;/p&gt;
          &lt;p&gt;Fur color: {{animal.furColor}}&lt;/p&gt;
          &lt;p&gt;Population: {{animal.population}}&lt;/p&gt;
          &lt;p&gt;Is extinct: {{animal.isExtinct}}&lt;/p&gt;
          &lt;p&gt;Is domesticated: {{animal.isDomesticated}}&lt;/p&gt;
  
      &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
      import axios from "axios";
  
      export default {
          props:  {
              animal:  {
                  name: {
                      type: String
                  },
                  furColor:  {
                      type: String
                  },
                  population: String,
                  isExtinct: String,
                  isDomesticated: String
              }
          },
  
          name: "DisplayAnimal",
  
          methods: {
  
          },
          created() {
              console.log("animal param: " +
                  JSON.stringify(this.$route.params.animal));
              this.animal = this.$route.params.animal;
          }
      };
  &lt;/script&gt;
  </code></pre>
  
  <p>The animal gets displayed just fine:</p>
  
  <p><a href="https://i.stack.imgur.com/dQJHe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dQJHe.png" alt="enter image description here"></a></p>
  
  <p>However I get the warning in console:</p>
  
  <p><a href="https://i.stack.imgur.com/YhAuP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YhAuP.png" alt="enter image description here"></a></p>
  
  <p>The <code>this.animal = this.$route.params.animal;</code> line that assigns the props explicitly is likely the cause of the warning.</p>
  
  <p>However if I remove that line the animal doesn't get displayed at all:</p>
  
  <p><a href="https://i.stack.imgur.com/0ne0O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0ne0O.png" alt="enter image description here"></a></p>
  
  <p>I have this </p>
  
  <p><strong>router.js</strong>:</p>
  
  <pre><code>{
      path: "/viewanimal",
      name: "viewanimal",
      component: () =&gt; import('./views/DisplayAnimal.vue'),
      props: {animal: true}
  },
  {
      path: "/getanimal",
      name: "getanimal",
      component: () =&gt; import('./views/GetAnimal.vue')
  }
  </code></pre>
  
  <p>I thought setting <code>props: {animal: true}</code> would make sure it's autoassigned, but it doesn't seem to be the case. How should I fix it?</p>