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

232
Views
How to integrate Javascript library in Laravel9 with Vue using Laravel Mix

new to all these modern day frameworks I'm trying to get this javascript library to work in my Vue component: https://clipboardjs.com

I can see it is integrated into my public/js/app.js file when Mix runs - but I cannot seem to be able to reference it from within my .vue (component) file

Can anyone give me a step by step guide on how to get this to integrate into my project please:

resources/js/app.js file

 import './clipboard'; 

the clipboard.js file is located at:

resources/js/clipboard.js

Mix webpack.mix.js file:

mix.js("resources/js/app.js", "public/js")
 .js("resources/js/clipboard.js", "public/js")
 .vue()
 .postCss("resources/css/app.css", "public/css", [
   require("tailwindcss"),
 ]);

My Vue component (method section):

<script>
    export default {
        props: ['mediaDetails'],
        data() {
            return {
            }
        },
        methods: {
              copyPassword() {
            alert("copy");
            var password = document.getElementById('#password');
            alert('1');
             var clipboard = new ClipboardJS(password);
            alert('2');
          }
        }

the alert('2') never fires due to the clipboard assignemnet failing

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

0

  1. First, in your webpack.mix.js file, remove the line .js("resources/js/clipboard.js", "public/js")
  2. Install the clipboard package: npm install clipboard
  3. In your Vue component, import the package in order to use it:
<script>
   import ClipboardJS from 'clipboard';

   export default {
       props: ['mediaDetails'],
       data() {
           return {
           }
       },
       methods: {
             copyPassword() {
           alert("copy");
           var password = document.getElementById('#password');
           alert('1');
            var clipboard = new ClipboardJS(password);
           alert('2');
         }
       }
  1. BTW You have a typo error in document.getElementById('#password'), it should be document.getElementById('password')
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!