enesser / vCards-js

Create vCards to import contacts into Outlook, iOS, Mac OS, and Android devices from your website or application.
MIT License
419 stars 155 forks source link

How can i make it work in vuejs? also in mobile #39

Open fabriguespe opened 5 years ago

fabriguespe commented 5 years ago

Please someone upload an implementation

pynner commented 5 years ago

Did you make any progress?

enesser commented 5 years ago

Would be nice to have a Vue and React component. However, for the purposes of Vue you should just be able to use vanilla JavaScript. I know at least one user has done this.

If I were trying to make it work entirely in the browser, I might try to use (with .getFormattedString()): https://stackoverflow.com/a/12006048

Except I would use a text/x-vcard as the mime-type instead of HTML.

Imperio8 commented 3 years ago

A simpler solution woud be:

const download = (vCardString, fileName) => {
    let fileURL = window.URL.createObjectURL(new Blob([vCardString]));
    let fileLink = document.createElement('a');
    fileLink.href = fileURL;
    fileLink.setAttribute('download', fileName);
    document.body.appendChild(fileLink);
    fileLink.click();
};

This should work in any js file. :)

mo9a7i commented 3 years ago

I used it on my NuxtJs code which is built on top of VueJS Just a simple npm install Then on the file Import vcard from 'vcards-js' And it works

Not sure what ur facing

carlosaroca commented 3 years ago

I used it on my NuxtJs code which is built on top of VueJS Just a simple npm install Then on the file Import vcard from 'vcards-js' And it works

Not sure what ur facing

Im doing the same but I dont know how use it in a component, I already import vcard like you

xrayian commented 1 year ago

hey, I am using typescript with my code and it won't let me set values to the vCard, so all I'm getting is start and end tag and a bunch of ;;;'s

here's my implementation

<script setup lang="ts">
import vCard from 'vcards-js';

//...

const generate_vCard = () => {
    vCard.firstName = 'Rayian';
    vCard.lastName = 'Mahi';
    console.log(vCard.getFormattedString())
    download(vCard.getFormattedString(), 'vcardFile.vcf')
};

The TS error I'm getting is Property 'firstName' does not exist on type '() => vCard'.ts(2339)

I can only access the attributes when I invoke the vCard function, but that wont let me set new values.

xrayian commented 1 year ago

hey, I am using typescript with my code and it won't let me set values to the vCard, so all I'm getting is start and end tag and a bunch of ;;;'s

here's my implementation

<script setup lang="ts">
import vCard from 'vcards-js';

//...

const generate_vCard = () => {
    vCard.firstName = 'Rayian';
    vCard.lastName = 'Mahi';
    console.log(vCard.getFormattedString())
    download(vCard.getFormattedString(), 'vcardFile.vcf')
};

The TS error I'm getting is Property 'firstName' does not exist on type '() => vCard'.ts(2339)

I can only access the attributes when I invoke the vCard function, but that wont let me set new values.

import vCardFactory from 'vcards-js';

const vCard = vCardFactory();

this fixed my issue