Giter Site home page Giter Site logo

ciaranpflanagan / vue-csv-import Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xlcrr/vue-csv-import

0.0 1.0 0.0 1.36 MB

Bulma implementation of vue-csv-import with 2 columns

License: MIT License

JavaScript 29.61% Vue 65.11% HTML 3.99% Shell 1.29%

vue-csv-import's Introduction

Vue.js component to handle CSV uploads with field mapping.

Latest Version on NPM Software License CircleCI Scrutinizer Code Quality

Demo

Demo

Go to the "demo" folder for a working example.

Installation

You can install the package via yarn:

yarn add vue-csv-import

or npm:

npm install vue-csv-import --save

Usage

Import component:

import { VueCsvImport } from 'vue-csv-import';

new Vue({
    components: { VueCsvImport },
    el: '#app',
});

Include in template:

<vue-csv-import url="/url/to/post" :map-fields="['array', 'of', 'field', 'names']"></vue-csv-import>

or with labels:

<vue-csv-import url="/url/to/post" :map-fields="{field1: 'Label 1', field2: 'Label 2'}"></vue-csv-import>

or with v-model:

<vue-csv-import v-model="parseCsv" :map-fields="{field1: 'Label 1', field2: 'Label 2'}"></vue-csv-import>

With all available slots:

<vue-csv-import
    v-model="csv"
    url="/hello"
    :map-fields="['name', 'age']">

    <template slot="hasHeaders" slot-scope="{headers, toggle}">
        <label>
            <input type="checkbox" id="hasHeaders" :value="headers" @change="toggle">
            Headers?
        </label>
    </template>

    <template slot="error">
        File type is invalid
    </template>

    <template slot="thead">
        <tr>
            <th>My Fields</th>
            <th>Column</th>
        </tr>
    </template>

    <template slot="next" slot-scope="{load}">
        <button @click.prevent="load">load!</button>
    </template>

    <template slot="submit" slot-scope="{submit}">
        <button @click.prevent="submit">send!</button>
    </template>
</vue-csv-import>

Options:

Option Default Description
mapFields N/A (required) These are the field names that the CSV will be mapped to
url null If present, the component will post the mapped values to this url. Otherwise, the component will only emit the value to be used as a normal input
callback null The callback to be called on successful upload. (url required)
catch null The function to be called on an error in posting (url required)
finally null The function to be called no matter what on posting (url required)
tableClass "table" The class to be added to table element
checkboxClass "form-check-input" The class to be added to the checkbox
buttonClass "btn btn-default" The class to be added to buttons
inputClass "form-control-file" The class to be added to the file input
submitBtnText "Submit" The value of the final submit button
loadBtnText "Submit" The value of the initial load file button
headers null Define whether csv has headers by default. Removes checkbox.
fileMimeTypes ["text/csv"] Array of valid mime types

Slots:

Slot Description
thead The content of "thead" in the field mapping table
next The next button. Use slot-scope "next" to load csv.
submit The submit button. Use slot-scope "submit" to submit form.
hasHeaders The "has headers" checkbox. Use slot-scope "toggle" and "headers".

Testing

npm run test

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please contact John Gile.

License

The MIT License (MIT). Please see License File for more information.

Credits

vue-csv-import's People

Contributors

jgile avatar xlcrr avatar acrisioscunha avatar ciaranpflanagan avatar tkaden4 avatar

Watchers

James Cloos avatar

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.