小编Ash*_*mar的帖子

如何在vue loader组件中导入JS脚本?

我有一个vue组件

vue-compoennt(vue-loader)

<template>
  <p>This is a template</p>
</template>
<script>
  require('main.js')
  huha()
</script>
Run Code Online (Sandbox Code Playgroud)

我有

main.js

 var huha = function(){
      alert("this is huha");
    }; 
alert("this is simple alert");
Run Code Online (Sandbox Code Playgroud)

在这里,我得到了"简单警报",但在评估huha()时,它显示了参考错误.有人可以帮我理解为什么会这样吗?

编辑

我试图使用testimonial.js如下,我得到参考错误.

    <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>
Run Code Online (Sandbox Code Playgroud)

它给出了"参考错误:证词没有定义"

javascript webpack vue.js babeljs

6
推荐指数
1
解决办法
9193
查看次数

标签 统计

babeljs ×1

javascript ×1

vue.js ×1

webpack ×1