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})

你可能感兴趣的:(vue.jsvue3watch)