Ash*_*mar 6 javascript webpack vue.js babeljs
我有一个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)
它给出了"参考错误:证词没有定义"
您需要像这样导出一个函数:
module.exports = {
huha: function(){
return alert("this is huha");
}
};
Run Code Online (Sandbox Code Playgroud)
然后在你的组件文件中:
<template>
<p>This is a template</p>
</template>
<script>
var main = require('main.js')
main.huha()
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9193 次 |
| 最近记录: |