同级、兄弟之前传输值

同级、兄弟之前传输值

signRelease 给 pieChartRate 传值。

在这里插入图片描述

步骤:
1、新建一个js作为桥梁。即创建一个Vue实例。
在这里插入图片描述

eventBus.js

import Vue from 'vue'
export default new Vue;

2、两个兄弟组件都需引入该js,引入为bus
3、signRelease 定义一个事件,点击或者是数据改变。我的是@change。
4、signRelease 中 e m i t 进 行 传 值 。 b u s . emit进行传值。bus. emitbus.emit(‘sendByBus’,传输的数据),sendByBus自行定义,两个兄弟组件需一致。
5、pieChartRate 中$on进行接收值。

代码

1、signRelease.vue作为传值者

<template>
    <div  @change="sendToMessage">
    <el-row :gutter="40" class="panel-group">
        <el-col :xs="24" :sm="24" :lg="6" class="card-panel-col">
            <div class="content">
                <div class="_content_title">标题</div>
                <div class="description">
                    <div class="_content_iteam">{{signReleaseData.noReleaseConfirmNum}}</div>
                </div>
            </div>
        </el-col>
    </el-row>
    </div>
</template>

<script>
import bus from '../../../../api/fault/eventBus';
import {getReleaseStatistics} from "@/api/fault/faultFlightDynamic";

export default {
    data(){
        return{
            signReleaseData:"",
        }
    },
    created(){
        this.getSignReleaseData();
    },
    methods:{
        //获取数据
        getSignReleaseData(){
            getReleaseStatistics().then((response) => {
                console.log("---接口返回--------", response);
                if (response.code == 0) {
                    this.signReleaseData = response.data;
                    console.log("---框框组件的值--------", this.signReleaseData);
		//调用该方法传值
                    this.sendToMessage();
                }
            });
        },
        sendToMessage(){
            bus.$emit('sendByBus',this.signReleaseData);
        },
    },
}

</script>

<style>
</style>

2、pieChartRate.vue,作为接收者

<template>
    <div :class="className" :style="{ height: height, width: width }" />
</template>
<script>
    import echarts from "echarts";
    require("echarts/theme/dark"); // echarts theme
    import resize from "./mixins/resize";
    import bus from '../../../../api/fault/eventBus';
    
    export default {
        mixins: [resize],
        props: {
            className: {
                type: String,
                default: "chart",
            },
            width: {
                type: String,
                default: "100%",
            },
            height: {
                type: String,
                default: "300px",
            },

        },
        data() {
            return {
                chart: null,
                chartData: {},
            };
        },
        mounted() {
			//获取到传递过来的值
            bus.$on('sendByBus',data =>{
                console.log("同级组件传过来的值:",data);
                this.chartData = data;
                this.$nextTick(() => {
                    this.initChart();
                });

            });

        },
        beforeDestroy() {
            if (!this.chart) {
                return;
            }
            this.chart.dispose();
            this.chart = null;
        },
        methods: {
            initChart() {
                this.chart = echarts.init(this.$el, "white");
                // this.chart = echarts.init(this.$el, "dark");

                this.chart.setOption({
                    title:[{
                        text: '进度\n' +this.chartData.percentage,
                        left: 'center',
                        top: 'center',
                        },
                        {
                        text: '进度统计表',
                        top: '1%',
                        // left:'30%',
                        textStyle:{
                            color:'black',
                            fontWeight:'346',
                            fontFamily:'sans-serif',
                            fontSize: 15
                        }
                    }
                    ],
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        top: '5%',
                        left: 'center',
                    },
                    series: [
                        {
                            color:[
                                '#0066FF',
                                '#cccccc',
                            ],
                            // name: 'Access From',
                            type: 'pie',
                            radius: ['60%', '50%'],
                            avoidLabelOverlap: false,
                            label: {
                                show: false,
                                position: 'right',
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    fontSize: '20',
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            data: [
                                { value: this.chartData.releaseConfirmNum, name: '已完成' },
                                { value: this.chartData.noReleaseConfirmNum, name: '未完成' },
                            ]
                        }
                    ]
                });
            },
        },
    };
</script>
<style>
</style>

浏览器打印结果:



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

怪异的bug

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值