Giter Site home page Giter Site logo

mrosendin / vue-bulma-pagination Goto Github PK

View Code? Open in Web Editor NEW
13.0 6.0 9.0 305 KB

Vue.js 2 Bulma pagination component

Home Page: https://mattrosendin.github.io/vue-bulma-pagination/

License: MIT License

HTML 5.10% Vue 62.57% JavaScript 32.33%
vue pagination bulma

vue-bulma-pagination's Introduction

Vue Bulma Pagination

npm version

A Vue.js pagination component for the Bulma CSS framework

View the demo.

Installation

Install via NPM:

npm install vue-2-bulma-pagination --save

Usage

Props

Name Type Required Default Description
current Number True N/A Current page
total Number False 0 Total number of items
itemsPerPage Number True N/A Items per page
step Number False 3 Number of pages to display (besides first and last)
onChange Function True N/A Page changed event callback. Parameters: page

Example

Use like below. See the example code in the demo.

<template>

  <table class="table">
    <thead>
      <tr>
        <th v-for="(key, value) in countries[0]">{{ key }}</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="country in countries">
        <td v-for="key in keys">{{ country[key] }}</td>
      </tr>
    </tbody>
  </table>

  <pagination
    :current="current"
    :total="total"
    :itemsPerPage="itemsPerPage"
    :onChange="onChange">
  </pagination>

</template>

<script>
import Pagination from 'vue-2-bulma-pagination'
import axios from 'axios';

let pagination = {
  current: 1,       // Current page
  total: 0,         // Items total count
  itemsPerPage: 5   // Items per page
}

export default {
  name: 'demo',
  components: { Pagination },
  data () {
    return {
      countries: [],
      pagination: pagination
    }
  },
  methods: {
    onChange (page) {
      console.log(`Getting page ${page}`)
      axios.get(`https://api.openaq.org/v1/countries?limit=5&page=${page}`)
      .then(response => {
        this.countries = response.data.results
        this.pagination.current  = page
      })
    }
  },
  created () {
    axios.get('https://api.openaq.org/v1/countries?limit=5')
    .then(response => {
      this.keys = Object.keys(response.data.results[0])
      this.countries = response.data.results

      // Set pagination config based on response
      this.pagination.total = response.data.meta.found
    })
  }
}
</script>

Development

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

For detailed explanation on how things work, consult the docs for vue-loader.

vue-bulma-pagination's People

Contributors

crimaniak avatar leeliwei930 avatar mrosendin avatar schlunsen avatar tlemens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue-bulma-pagination's Issues

Warning: component lists rendered with v-for should have explicit keys

It needs additional 'key' attribute at Pagination.Vue line 7.
Like <component v-for="element in elements" :key="element.page" ...>

Full message text from Webpack:

./~/vue-loader/lib/template-compiler?{"id":"data-v-62cc492c","transformToRequire":{"audio":"src"}}!./~/vue-loader/lib/selector.js?type=template&index=0!./~/vue-2-bulma-pagination/src/Pagination.vue
(Emitted value instead of an instance of Error) <component v-for="element in elements">: component lists rendered with v-for should have explicit keys. See https://vuejs.org/guide/list.html#key for more info.
 @ ./~/vue-2-bulma-pagination/src/Pagination.vue 9:2-200
 @ ./~/vue-2-bulma-pagination/index.js
 @ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/BasicTable.vue
 @ ./src/components/BasicTable.vue
 @ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/home/device-selector.vue
 @ ./src/components/home/device-selector.vue
 @ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/home/page.vue
 @ ./src/components/home/page.vue
 @ ./src/router/index.js
 @ ./src/main.js
 @ multi ./build/dev-client ./src/main.js

Error in readme

Can you please fix code example:
import Pagination from 'vue-2-pagination-bulma'
to
import Pagination from 'vue-2-bulma-pagination'

Event emitter

Hi!

Can you please explain what is the reason to use function onChange instead of emitting event @change?

Import failed

When importing
import Pagination from "vue-2-bulma-pagination";
Module build failed: Error: Couldn't find preset "env" relative to directory "*\node_modules\vue-2-bulma-pagination"

Possible fix maybe you need to commit .env file? Because for now it is in .npmignore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.