vCards-js icon indicating copy to clipboard operation
vCards-js copied to clipboard

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

Open humanagent opened this issue 5 years ago • 7 comments

Please someone upload an implementation

humanagent avatar May 04 '19 15:05 humanagent

Did you make any progress?

pynner avatar May 09 '19 12:05 pynner

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.

enesser avatar May 09 '19 21:05 enesser

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. :)

Imperio8 avatar May 10 '21 11:05 Imperio8

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

mo9a7i avatar May 16 '21 12:05 mo9a7i

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

carlosaroca avatar Jun 25 '21 15:06 carlosaroca

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 avatar Aug 07 '22 17:08 xrayian

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

xrayian avatar Aug 08 '22 16:08 xrayian