SoFunction
Updated on 2025-04-05

Solve the problem of vue2 inability to get variables in prop in mounted function

As shown below;

props: {
 example: {
  type: Object,
  default() {
  },
 },
},
watch: {
 example: function(newVal,oldVal){
 // newVal is the changed value  // Continue to the event to be processed },
},

Use watch instead of mounted.

The watch attribute responds to changes in data and performs asynchronous operations when the data changes.

Summarize

The above is the problem that the editor introduced to you to solve the problem that the variables in the mounted function of vue2 cannot be obtained in the prop. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!