父组件传递参数给子组件,子组件根据参数的变化, export default { name: 'event-classify', props: ['time'], data() { return { loading: true, nodeName: '重庆路桥股份有限公司', eventTypes: [], // 事件分类列表
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);
});
}
}
};
