How to import JS script into vue loader component?

I have vue-component

vue-compoennt (vue-loader)

<template> <p>This is a template</p> </template> <script> require('main.js') huha() </script> 

And I have

main.js

  var huha = function(){ alert("this is huha"); }; alert("this is simple alert"); 

Here I get a "simple warning", but when evaluating huha () it shows a reference error. Can someone please help me understand why this is happening?

Edit

I try to use testimonial.js as shown below and get a link to the error.

  <template> <p>This is a template</p> <div id="testimonial-slider"></div> </template> <script> require('testimonial/testimonial.js') require('testimonial/testimonial.css') var testimonial = new Testimonial('#testimonial-slider'); </script> <style> p{ color: red; } </style> 

It gives a "control error: review not defined"

+5
source share
1 answer

You need to export such a function:

 module.exports = { huha: function(){ return alert("this is huha"); } }; 

And then in your component file:

 <template> <p>This is a template</p> </template> <script> var main = require('main.js') main.huha() </script> 
+1
source

Source: https://habr.com/ru/post/1012839/


All Articles