简体   繁体   English

将数据从一个组件传递到另一个Vuejs

[英]Emmiting Data from one component to another Vuejs

this is my Table component. 这是我的表组件。

<b-table
    class="table table-striped"
      id="my-table"
      :items="items"
      :per-page="perPage"
      :current-page="currentPage"
      :fields="fields"
      @row-clicked="test"
      lg
    ></b-table>

method on the same component: 相同组件上的方法:

methods: {
    test(){
        console.log('test')
        this.$emit('rowClick',"heyoooooooo")
    }
},

parent component: 父组件:

    <ClientTable :fields="fields" :items="rows" :sortBy="sortBy" :sortDesc="sortDesc" @rowClicked="Callme()"/>

parent method: 父方法:

methods: {
    Callme(e){
        console.log('hee')
    }
},

I'm really new with VueJS and I stumbled with Emit I was wondering why is my code not working, does not console anything. 我对VueJS真的很陌生,对Emit迷迷糊糊,我想知道为什么我的代码无法正常工作,无法进行任何操作。

thanks 谢谢

I recreate your question and it's works well. 我重新提出您的问题,并且效果很好。

 Vue.config.devtools = false Vue.config.productionTip = false Vue.component('client-table', { props: ['items'], methods: { test(){ this.$emit('row-clicked',"heyoooooooo") } }, template: ` <b-table class="table table-striped" :items="items" lg @row-clicked="test" ></b-table> ` }) new Vue({ el: "#app", data: { rows: [ { 'heading 1': 'table cell', 'heading 2': 'table cell', 'heading 3': 'table cell' }, { 'heading 1': 'table cell', 'heading 2': 'table cell', 'heading 3': 'table cell' }, { 'heading 1': 'table cell', 'heading 2': 'table cell', 'heading 3': 'table cell' }, ] }, methods: { Callme (e) { console.log(e) } } }) 
 <link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css" /> <link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css" /> <div id="app"> <client-table :items="rows" @row-clicked="Callme"> </client-table> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <script src="https://unpkg.com/bootstrap-vue@2.0.0-rc.28/dist/bootstrap-vue.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM