Madasu K
Madasu K

Reputation: 1863

vuejs2 copy clipboard issue

I am trying to use https://alligator.io/vuejs/vue-clipboard-copy/ for copy clip board feature in Vue.js, it is working fine for string but when I have an object, it is not copying properly. Below is the sample code.

<button v-clipboard:copy="test">Copy</button>

if test is a simple string then I am getting that string properly copied to clipboard as abc in this case.

data() {
        return {
            test: 'abc'
        }
    }

But when I give,

data() {
        return {
            test: {name: 'abc'}
        }
    }

I am getting [object object] into my clipboard instead {name: 'abc'}

Upvotes: 2

Views: 3535

Answers (2)

Tony Tom
Tony Tom

Reputation: 1583

Try this way

<button v-clipboard:copy="stringConvertion">Copy</button>

  computed:{
   stringConvertion: function () {
    return JSON.stringify(test);
   }
  }

Upvotes: 3

Sajib Khan
Sajib Khan

Reputation: 24174

Try this:

<button v-clipboard:copy="JSON.stringify(test)">Copy</button>

Upvotes: 1

Related Questions