乐趣区

关于vue.js:vue3-provide-inject-父子组件传值watch监听

父组件

setup () {
   const data = reactive({deviceTypesTotal: {}
})

provide('deviceTypesTotal', data.deviceTypesTotal)

子组件

import {defineComponent, reactive, toRefs, ref, onMounted, inject , watch} from 'vue'

const deviceTypesTotal = inject('deviceTypesTotal')
watch(deviceTypesTotal, (newValue) => {console.log(newValue)
  data.deviceTypesTotal = newValue.deviceTypesTotal
},{deep:true})
退出移动版