适用场景是
父组件

<template>
  <view>
      <cylindrical :haveTask="totals"></cylindrical>
  </view>
</template>

<script>
  import cylindrical from '@/pagesB/componentsB/cylindrical.vue'
  export default {
    components: {
      cylindrical
    },
    data() {
      return {
        totals: [], //数据
      }
    }
  }
</script>

<style lang="scss">
  
</style>

子组件

<template>
  <view >
    <view>
    {{haveTask}}
    </view>
  </view>
</template>

<script>
  // import time from '@/basejs/time';
  export default {
    props: {
      haveTask: Array,
    },
    data() {
      return {
      }
    },
    watch: {
    //haveTask 为接收参数的名称
      haveTask: {
        handler(newValue,oldValue) {
          this.circulation();//监听到数据变化执行方法
        },
        deep: true // 深度监听父组件传过来对象变化
      }
    },
    methods: {
      circulation() {
           console.log('已经监听到数据变化')
      },
    }
  };
</script>

<style>

</style>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐