VUEJS同胞组件数据通过方法传递

发布于 2025-02-07 17:06:48 字数 1888 浏览 0 评论 0原文

我有一个vuejs laravel页面,上面有父母,

我的父模板中有

<template>
<div>
    <h4>DATA ANALYSIS</h4>
    <dataAnalysisGraph />
    <br>
    <hr>
    <dataAnalysisTable />
</div>  

2个孩子,在我的dataAnalissisgraph子组件中,我有一种方法,每次下拉下订单更改时都会发送请求。

    //dataAnalysisGraph 
    <template> 
          <div>
              <div> 
                <select class="form-control select" name="" @change="GenerateChart" v-model='chartType' >
                  <option value="1">One</option>
                  <option value="2">Two</option>
                  <option value="3">Three</option>
            
                </select>
              </div>
          
            <br><br><br>
              <highcharts class="hc" :options="chartOptions" ref="chart"></highcharts>
          </div>
        </template>
    <script>
export default {
    data() {
        return {
        data: [],
        }
    },
    methods: {
        GenerateChart(){
            this.axios
                .get('api/'+this.chartType)
                .then(response => {
                    this.data = response.data;
                   
            });
        },
    },
    created() {
        this.GenerateChart();
    },      
};
</script>

在我的DataAnalysistist of子组件中。我想从dataAnalysisgraph组件中获取this.data,并将其传递给DataAnalysistsist,并每次下拉列表形式dataAnalissisgraph组件更改时都会对其进行更新。

这是我当前可数据的可及组件

<template>
    <div>
        {{data}}
    </div>
    
</template>
<script>
export default {
    data() {
        return {
        data: [],
        };
    },
    methods: {
        
    },
    created() {
       
    },      
};
</script>

I have a Vuejs Laravel page with Parent and 2 child

In my Parent template I have

<template>
<div>
    <h4>DATA ANALYSIS</h4>
    <dataAnalysisGraph />
    <br>
    <hr>
    <dataAnalysisTable />
</div>  

and in my dataAnalysisGraph child component i have a method that send request everytime the dropdown changes.

    //dataAnalysisGraph 
    <template> 
          <div>
              <div> 
                <select class="form-control select" name="" @change="GenerateChart" v-model='chartType' >
                  <option value="1">One</option>
                  <option value="2">Two</option>
                  <option value="3">Three</option>
            
                </select>
              </div>
          
            <br><br><br>
              <highcharts class="hc" :options="chartOptions" ref="chart"></highcharts>
          </div>
        </template>
    <script>
export default {
    data() {
        return {
        data: [],
        }
    },
    methods: {
        GenerateChart(){
            this.axios
                .get('api/'+this.chartType)
                .then(response => {
                    this.data = response.data;
                   
            });
        },
    },
    created() {
        this.GenerateChart();
    },      
};
</script>

In my dataAnalysisTable child component. I want to get the this.data from dataAnalysisGraph component and pass it to the dataAnalysisTable and updates it every time the dropdown form dataAnalysisGraph component changes.

this is my dataAnalysisTable component currently

<template>
    <div>
        {{data}}
    </div>
    
</template>
<script>
export default {
    data() {
        return {
        data: [],
        };
    },
    methods: {
        
    },
    created() {
       
    },      
};
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

维持三分热 2025-02-14 17:06:48

您可以在DataAnalysisgraph内部发出一个事件,将this.data返回到父,并使用V-Model将此值连接到DataAnalysistable的组件。您可以阅读更多在VUEJS指南中在“使用V-Model”的“使用”中,部分。

You can emit an event inside dataAnalysisGraph returning this.data to the parent and connect this value using v-model to the dataAnalysisTable component. You can read more in the vuejs guide specifically in the "Usage with v-model" section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文