查看“︁JavaScript/vue.js/事件车”︁的源代码
来自康健生活
←
JavaScript/vue.js/事件车
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 引言 == 在传值中一种通用的方法是使用事件车,<s>我一般用它做分页组件的传值处理</s>(分页组件现在改用 store 处理) == 格式 == 事件车的格式 在子组件,如分页组件中使用: <syntaxhighlight lang="html5"> <!-- @auther kangkk @date 2020/7/13 @desc 分页组件 --> <template> <el-pagination v-if="isShowPagination" background :class="$style.pagination" :style="{ width: width, height: heightVaule, padding: paddingValue, }" :current-page.sync="currentPage" :page-size="pageSize" :pager-count="pageCount" layout="pager, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange"/> </template> <style module lang="scss">@import "./index";</style> <script> import EventBus from '@@/plugins/bus.js' export default { name: 'ListPagination', data () { return { height: 30, currentPage: 1, pageCount: 5, total: 0, pageSize: 10, } }, props:{ width:{ type: String, default:()=>'700px' }, padding:{ type: Array, default:()=>[0,0,0,0] } }, computed: { isShowPagination () { return this.total > this.pageSize }, heightVaule (){ return this.padding[0] + this.height + this.padding[2] + 'px' }, paddingValue (){ return this.padding.join('px ') } }, created () { this.servicePaginationEventMessage() }, methods: { handleSizeChange (pageSize) { this.paginationEvent(pageSize, this.currentPage) }, handleCurrentChange (currentPage) { this.paginationEvent(this.pageSize, currentPage) }, /** * 事件车发送客户端分页数据的第几页 */ paginationEvent (pageSize, currentPage) { EventBus.$emit('clientPagination', { total: this.total, currentPage: currentPage, pageCount: this.pageCount, pageSize: pageSize }) }, /** * 事件车接收服务端分页数据的第几页 */ servicePaginationEventMessage () { const _self = this EventBus.$on('servicePagination', (event) => { console.log(event) _self.currentPage = event.currentPage _self.total = event.total _self.pageSize = event.pageSize || 10 }) } } } </script> </syntaxhighlight> 在父组件中调用分页 <syntaxhighlight lang="html5"> <template> <div class="lattice-width padding-top"> <ly-pagination class="padding-top text-center" :padding="[20,0,20,0]" :width="'1010px'"/> </div> </template> <script> import ComPagination from '@@/components/pagination/index.vue'; import EventBus from '@@/plugins/bus.js'; export default { name: 'Home', scrollToTop: true, components: { 'ly-pagination': ComPagination }, mounted () { this.servicePaginationEvent(); }, methods: { /** * 事件车发送服务端传来的分页信息 * @param allNum * @param paginationCurrentPage * @param searchTab */ servicePaginationEvent (allNum, paginationCurrentPage, searchTab) { EventBus.$emit('servicePagination', { total: 100, currentPage: 1 }); }, } }; </script></syntaxhighlight>
返回
JavaScript/vue.js/事件车
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。