Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that the mounted in the Vue sub-component cannot get the value in the props?

Shulou Source: shulou.com Published: 2022-05-31 20:00:13 09月21日 Update

This article Xiaobian introduces in detail for you "Vue sub-component mounted can not get the value of props how to solve", the content is detailed, the steps are clear, the details are handled properly, I hope that this "Vue sub-component mounted can not get the value of props" article can help you solve doubts, the following with Xiaobian's ideas slowly in-depth, together to learn new knowledge.

The subcomponent mounted cannot get the value of props

Problem: passing to the subcomponent to the data is called from the interface, causing the empty object or array to be passed to the subcomponent when the page is created

Method one

Use watch to listen for changes in the median value of props

Method 2 (recommended)

Add v-if judgment when calling subcomponents to determine whether there is data in the array or object.

Component props cannot get a value for the first time, plus sync uses v-if

Remember to define data= in data []

Use watchprops: [data] watch: {date (newValue, oldValue) {if (newValue! = = oldValue) {this.id = this.data [0] .id console.log ('date', this.id)} in sub-components. This is the end of this article on "how to solve the problem that mounted can not get the value in props in Vue sub-components". If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the articles, you are welcome to follow the industry information channel.

Tags: Components articles content objects data arrays methods time appropriate median suggestions ideas interfaces new knowledge more steps knowledge knowledge points first time article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology vpn macOS Shulou Tech Info