A
A
Andrey Pike2021-03-24 11:42:05
typescript
Andrey Pike, 2021-03-24 11:42:05

He swears that I prop mutate, why?

I don't change the prop href, but the console says "Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders." Why? Through getter/computed does not help at all. Everything works, but a warning spits into the console.

<template>
  <div>
    <a :href="href" target="_blank">
      <slot>[Default slot]</slot>
    </a>
    <slot name="named-1">[Default named slot 1]</slot>
    <slot name="named-2">[Default named slot 2]</slot>
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';

@Component
export default class SlotsComponent extends Vue {
  @Prop(String)
  href = '';
}
</script>


605afb11e1b3b415283280.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-03-24
@0xD34F Vue.js

I don't change the prop href

What about trying to set a default value? Maybe it is considered as a parameter mutation:
@Prop(String)
href = '';

Attempt, by the way, a curve :
It's not supported to define each defaultproperty like @Prop() prop = 'default value'.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question