setup watch监听vuex值

import { reactive, ref, toRefs, onMounted, getCurrentInstance, computed, watch } from 'vue'
import { useStore } from 'vuex'
    // vuex 
    const store = useStore()
    const changeTextName = () =>{
      store.dispatch('commitTextName', '修改了哦!')
    }
 
    console.log('store', store.state.textName)
    watch(() => store.state.textName, (val, old) => {
      console.log(val, old)
    })
    
     // vuex  deep 深度监听,第三个参数加上{deep:true}
 
 
      watch(
        () => store.state.textName, 
          (val, old) => {
              console.log(val, old)
         }, 
      {
        deep: true
      }
    )
  
posted @ 2021-08-05 18:05  敲敲碰碰  阅读(927)  评论(0编辑  收藏  举报