vue monitor watch usage

watch monitoring must be monitored:属性值 , that is, the datavalue

case

  data () {
    return {
      language: ''
    }
  },
  methods: {
    handleSetLanguage (lang) {
      this.$i18n.locale = lang;
      this.language = lang;
      localStorage.setItem("lang", lang);
    }
  },
  watch: {
    language: {
      handler (val) {
        console.log(val, '改变了');
        if (val) {
          this.menuList = [{
            title: this.$t('navTop.aboutAllianceChain'),
            active: true,
          },
          {
            title: this.$t('navTop.metaUniverseMerchantAlliance'),
            active: false,
          },
          {
            title: this.$t('navTop.nftTradingPlatform'),
            active: false,
          },
          {
            title: this.$t('navTop.projectCommunity'),
            active: false,
          },
          {
            title: this.$t('navTop.newsAnnouncement'),
            active: false,
          },
          {
            title: this.$t('navTop.buyDag'),
            active: false,
          },
          {
            title: this.$t('navTop.purchaseGenesisNode'),
            active: false,
          },]
        }
      },
      immediate: true // 代表进入页面首先执行
    }
  },

If you feel that the article is good, remember to pay attention, pay attention and collect it. Please correct me if there is any mistake. If you need to reprint, please indicate the source, thank you! ! !

Guess you like

Origin blog.csdn.net/m0_49714202/article/details/124447040