admin管理员组文章数量:1430848
I have a vue-ponent
vue-poennt (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 the 'simple alert' but in assessing huha() it is showing reference error. Can someone please help me to understand why is this happening?
Edit
I am trying to use testimonial.js as following and I am getting reference 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 is giving "reference error: Testimonial is not defined"
I have a vue-ponent
vue-poennt (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 the 'simple alert' but in assessing huha() it is showing reference error. Can someone please help me to understand why is this happening?
Edit
I am trying to use testimonial.js as following and I am getting reference 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 is giving "reference error: Testimonial is not defined"
Share Improve this question edited Dec 27, 2015 at 2:31 loganfsmyth 162k31 gold badges346 silver badges258 bronze badges asked Dec 9, 2015 at 15:33 Ashvini KumarAshvini Kumar 1071 gold badge3 silver badges7 bronze badges 4- Can I see your ponent code? – Yauheni Prakopchyk Commented Dec 9, 2015 at 17:23
- Actually i am using vue-loader webpack in this app. So in vue-ponent we write html, script and style in same file with extension '. vue-ponent' so i haven't defined a separate ponent. My ponent is 'vue-ponent' – Ashvini Kumar Commented Dec 9, 2015 at 17:44
-
module.exports
only works with a pilar, like browserify. Whats your build process? – notANerdDev Commented Dec 10, 2015 at 4:58 - 1 I am using webpack. I am also using vue-loader – Ashvini Kumar Commented Dec 10, 2015 at 5:03
1 Answer
Reset to default 1You need to export a function like so:
module.exports = {
huha: function(){
return alert("this is huha");
}
};
And then in you ponents file:
<template>
<p>This is a template</p>
</template>
<script>
var main = require('main.js')
main.huha()
</script>
本文标签: javascriptHow to import JS script in vue loader componentStack Overflow
版权声明:本文标题:javascript - How to import JS script in vue loader component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745567061a2663824.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论