2

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'}

Madasu K
  • 1,813
  • 2
  • 38
  • 72

2 Answers2

3

Try this way

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

  computed:{
   stringConvertion: function () {
    return JSON.stringify(test);
   }
  }
Tony Tom
  • 1,435
  • 1
  • 10
  • 17
1

Try this:

<button v-clipboard:copy="JSON.stringify(test)">Copy</button>
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73