Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

703
Views
How do I add a button that would copy displayed text in vue.js?

I'm trying to add a button that would enable me to copy a snippet of code that is in view to the clipboard for a code catalog application in vue.js.

When I use the vue clipboard library and attempt this in the example component:

<div class="full-screen-code-snippet">
  {{ example.codeSnippet }}
</div>

<div class="full-screen-copy-button">
<button v-clipboard:copy="example.codeSnippet"></button>    
</div>

the snippet displays properly but the button does not. What's going on? How should I go about making this button?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should be using it like : v-clipboard="variableName" or with :copy the same . you can read more about it here or this one

<template id="t">
  <div class="container">
    <input type="text" v-model="message">
    <button type="button"
      v-clipboard:copy="message"
      v-clipboard:success="onCopy"
      v-clipboard:error="onError">Copy!</button>
  </div>
</template>

<script>
new Vue({
  el: '#app',
  template: '#t',
  data: function () {
    return {
      message: 'Copy These Text'
    }
  },
  methods: {
    onCopy: function (e) {
      alert('You just copied: ' + e.text)
    },
    onError: function (e) {
      alert('Failed to copy texts')
    }
  }
})
</script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!