How to monitor props in Vue3.0
This article mainly explains "how to monitor props in Vue3.0". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to monitor Props in Vue3.0.
The first way for Vue3.0 to listen to props
Listen to this props directly
Export default defineComponent ({props: {isOpen: Boolean,}, emits: {"close-modal": null,}, setup (props, context) {watch (props, (newProps) = > {console.log (newProps.isOpen); / / see the new value} here); const closeModal = () = > {context.emit ("close-modal");} Return {closeModal,};},}); second kind
Monitor one of the attributes in it
Export default defineComponent ({props: {isOpen: Boolean,}, emits: {"close-modal": null,}, setup (props, context) {watch (() = > props.isOpen, (newProps) = > {console.log (newProps); / / View new values}); const closeModal = () = > {context.emit ("close-modal");} Return {closeModal,};},}); vue3.0 listens to props for data echo import {defineComponent, reactive, watch} from 'vue' Export default defineComponent ({name: "from", props: {record: {type: Object, default: null,}}, setup: function (props, context) {const formState = reactive ({headPic:', nickname:', password:', username:', roleDomainList: []}) / * listen to props*/ watch (props, (nweProps, oldProps) = > {for (let item in formState) {formState [item] = nweProps.record [item];}}); return {formState} }}) Thank you for your reading. The above is the content of "how to monitor props in Vue3.0". After the study of this article, I believe you have a deeper understanding of how to monitor props in Vue3.0, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!