Vue component props error reporting problem

Encountered the following error:

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "selectType" 

The reason is that after I received the props, I modified it inside the component, and then passed it to the parent component, and then an error was thrown: In this case, this error will be reported, because the value in the passed in prop is not allowed to change. This will only appear after the vue update. The Internet says this:

In vue2, modifying props directly is considered an anti-pattern. Since in the new rendering mechanism the child component will be overwritten every time the parent component re-renders, props should be treated as immutable objects^1.

You can't change the quantity prop to synchronize with the parent component, but let this component submit an event to the parent component, you can watch the quantity variable, and emit the event if the variable changes, so no prop is needed here at all

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325558910&siteId=291194637
Recommended