Vue中如何设置一个基于watch的深度观察者?

更新于
2026-09-29 13:15:03
1阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计222个文字,预计阅读时间需要1分钟。

Vue中如何设置一个基于watch的深度观察者?

父组件通过传递参数给子组件,子组件根据参数的变化进行数据处理,并导出默认对象,包含组件名称、可接收的属性和初始数据状态:`name: 'event-classify', props: ['time'], data() { return { loading: true, nodeName: '重庆路桥股份有限公司', eventTypes: [] }; }`

Vue中如何设置一个基于watch的深度观察者?

父组件传递参数给子组件,子组件根据参数的变化,

export default { name: 'event-classify', props: ['time'], data() { return { loading: true, nodeName: '重庆路桥股份有限公司', eventTypes: [], // 事件分类列表 eventCounts: [] // 事件次数列表 }; }, mounted: function () { this.$nextTick(function () { this.getData(); }); }, watch: { // 如果 time 发生改变,这个函数就会运行 time: function (newTime) { console.log(newTime); this.getData(); } }, methods: { // 获取收据 getData: function () { axios.post('overview/eventTypeList', { companyName: this.nodeName, time: this.time }).then((res) => { if (res.data.success) { this.loading = false; let obj = res.data.obj; this.eventTypes = obj.eventTypes; this.eventCounts = obj.eventCounts; } }).catch((error) => { console.log(error); }); } } };

本文共计222个文字,预计阅读时间需要1分钟。

Vue中如何设置一个基于watch的深度观察者?

父组件通过传递参数给子组件,子组件根据参数的变化进行数据处理,并导出默认对象,包含组件名称、可接收的属性和初始数据状态:`name: 'event-classify', props: ['time'], data() { return { loading: true, nodeName: '重庆路桥股份有限公司', eventTypes: [] }; }`

Vue中如何设置一个基于watch的深度观察者?

父组件传递参数给子组件,子组件根据参数的变化,

export default { name: 'event-classify', props: ['time'], data() { return { loading: true, nodeName: '重庆路桥股份有限公司', eventTypes: [], // 事件分类列表 eventCounts: [] // 事件次数列表 }; }, mounted: function () { this.$nextTick(function () { this.getData(); }); }, watch: { // 如果 time 发生改变,这个函数就会运行 time: function (newTime) { console.log(newTime); this.getData(); } }, methods: { // 获取收据 getData: function () { axios.post('overview/eventTypeList', { companyName: this.nodeName, time: this.time }).then((res) => { if (res.data.success) { this.loading = false; let obj = res.data.obj; this.eventTypes = obj.eventTypes; this.eventCounts = obj.eventCounts; } }).catch((error) => { console.log(error); }); } } };