Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events Vue-tables-2网格组件使用,如何使用事件总线?_Events_Vue.js_Vue Tables 2 - Fatal编程技术网

Events Vue-tables-2网格组件使用,如何使用事件总线?

Events Vue-tables-2网格组件使用,如何使用事件总线?,events,vue.js,vue-tables-2,Events,Vue.js,Vue Tables 2,我试图发现这个matfish2/vue-tables-2组件,基本用法还可以,但要在文档中的漏洞中阅读是很棘手的。。。谷歌上的例子不多 文件中规定: 事件 Using Custom Events (For child-parent communication): <v-server-table :columns="columns" url="/getData" @loaded="onLoaded"></v-server-table> Using the event bu

我试图发现这个matfish2/vue-tables-2组件,基本用法还可以,但要在文档中的漏洞中阅读是很棘手的。。。谷歌上的例子不多

文件中规定:

事件

Using Custom Events (For child-parent communication):

<v-server-table :columns="columns" url="/getData" @loaded="onLoaded"></v-server-table>
Using the event bus:
Event.$on('vue-tables.loaded', function (data) {
    // Do something
});
使用自定义事件(用于子-父通信):
使用事件总线:
事件。$on('vue-tables.loaded',函数(数据){
//做点什么
});
所以我在我的UsersPage.vue中尝试了它

<template>
  <div id="users" class="container">
    <div class='users'>
      <v-client-table :data='tableData' :columns='columns' :options='options' @loaded="onLoaded"></v-client-table>
    </div>
  </div>
</template>


<script>
import { Event } from 'vue-tables-2'
export default {
  name: 'UsersPage',
  data () {
    return {
      columns: ['id', 'firstName', 'lastName', 'email', 'birthday'],
      tableData: [ ... ],
      options: {
        perPage: 5,
        perPageValues: [ 5, 10, 15, 20 ]
      }
    }
  },
  ready: function () {
    Event.$on('vue-tables.loaded', (data) => {
      console.log('Loaded...')
    })
  }
}
</script>

从“vue-tables-2”导入{Event}
导出默认值{
名称:'UsersPage',
数据(){
返回{
列:['id'、'firstName'、'lastName'、'email'、'birth'],
tableData:[…],
选项:{
每页:5,
perPageValues:[5,10,15,20]
}
}
},
就绪:函数(){
事件。$on('vue-tables.loaded',(数据)=>{
console.log('Loaded…'))
})
}
}
但它不起作用。。。我错在哪里?如何检查这些事件? 谢谢你的反馈

更新

我请求修改我的UsersPage脚本如下,没有错误,也没有控制台日志

<script>
import Vue from 'vue'
import { Event } from 'vue-tables-2'
Vue.use(Event)
export default {
  name: 'UsersPage',
  data () {
    return {
      columns: ['id', 'firstName', 'lastName', 'email', 'birthday'],
      tableData: [ ... ],
      options: {
        perPage: 5,
        perPageValues: [ 5, 10, 15, 20 ]
      }
    }
  },
  created () {
    Event.$on('vue-tables.loaded', function (data) {
      console.log('Loaded...')
      console.log('My event has been triggered', data)
    })
  },
  methods: {
    onLoaded ($event) {
      console.log('My event caught in global event bus', $event)
    }
   }
  }
</script>

从“Vue”导入Vue
从“vue-tables-2”导入{Event}
Vue.use(事件)
导出默认值{
名称:'UsersPage',
数据(){
返回{
列:['id'、'firstName'、'lastName'、'email'、'birth'],
tableData:[…],
选项:{
每页:5,
perPageValues:[5,10,15,20]
}
}
},
创建(){
事件。$on('vue-tables.loaded',函数(数据){
console.log('Loaded…'))
console.log('我的事件已被触发',数据)
})
},
方法:{
已加载($event){
console.log('My event capture in global event bus',$event)
}
}
}

阅读不推荐使用的Vue表格版本后。。。。我发现此事件仅在服务器端触发。。。不是客户。。。 该文档缺少很多示例,对于Vue.js的新手来说很难理解

vue-tables.loaded(服务器端)

将响应数据附加到表后激发。通过响应发送