欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue3.0中如何監(jiān)聽props方法

 更新時(shí)間:2022年04月18日 15:33:23   作者:LJJ_3  
這篇文章主要介紹了Vue3.0中如何監(jiān)聽props方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Vue3.0如何監(jiān)聽props

學(xué)習(xí)vue3.0記錄下props監(jiān)聽:

第一種

直接監(jiān)聽這個(gè)props

export default defineComponent({
? props: {
? ? isOpen: Boolean,
? },
? emits: {
? ? "close-modal": null,
? },
? setup(props, context) {
? ? watch(
? ? ? props,
? ? ? (newProps) => {
? ? ? ? console.log(newProps.isOpen); //這里看到新值
? ? ? }
? ? );
? ? const closeModal = () => {
? ? ? context.emit("close-modal");
? ? };
? ? return {
? ? ? closeModal,
? ? };
? },
});

第二種

監(jiān)聽里邊的某一個(gè)屬性

export default defineComponent({
? props: {
? ? isOpen: Boolean,
? },
? emits: {
? ? "close-modal": null,
? },
? setup(props, context) {
? ? watch(
? ? ? () => props.isOpen,
? ? ? (newProps) => {
? ? ? ? console.log(newProps);//查看新值
? ? ? }
? ? );
? ? const closeModal = () => {
? ? ? context.emit("close-modal");
? ? };
? ? return {
? ? ? closeModal,
? ? };
? },
});

vue3.0監(jiān)聽props做數(shù)據(jù)回顯

<template>
</template>
<script>
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: []
    });
    /*監(jiān)聽props*/
    watch(props, (nweProps, oldProps) => {
      for (let item in formState) {
        formState[item] = nweProps.record[item];
      }
    });
    return {
      formState
    };
  }
})
</script>
<style scoped>
</style>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue 表情包輸入組件的實(shí)現(xiàn)代碼

    Vue 表情包輸入組件的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Vue 表情包輸入組件的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01
  • vue雙向數(shù)據(jù)綁定原理分析、vue2和vue3原理的不同點(diǎn)

    vue雙向數(shù)據(jù)綁定原理分析、vue2和vue3原理的不同點(diǎn)

    這篇文章主要介紹了vue雙向數(shù)據(jù)綁定原理分析、vue2和vue3原理的不同點(diǎn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 建立和維護(hù)大型 Vue.js 項(xiàng)目的 10 個(gè)最佳實(shí)踐

    建立和維護(hù)大型 Vue.js 項(xiàng)目的 10 個(gè)最佳實(shí)踐

    這篇文章小編要與大家分享的是建立和維護(hù)大型 Vue.js 項(xiàng)目的 10 個(gè)最佳實(shí)踐,需要的小伙伴請(qǐng)和小編一起學(xué)習(xí)下面文章的具體內(nèi)容吧
    2021-09-09
  • vue中的vendor.js文件過(guò)大問(wèn)題及解決

    vue中的vendor.js文件過(guò)大問(wèn)題及解決

    這篇文章主要介紹了vue中的vendor.js文件過(guò)大問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue2中實(shí)現(xiàn)dialog的封裝方式

    Vue2中實(shí)現(xiàn)dialog的封裝方式

    這篇文章主要介紹了Vue2中實(shí)現(xiàn)dialog的封裝方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • vue 導(dǎo)航守衛(wèi)和axios攔截器有哪些區(qū)別

    vue 導(dǎo)航守衛(wèi)和axios攔截器有哪些區(qū)別

    這篇文章主要介紹了vue 導(dǎo)航守衛(wèi)和axios攔截器有哪些區(qū)別,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下
    2020-12-12
  • 最新評(píng)論