工作中需要使用vue框架,有的时候npm能下载的js并不够于平时的开发,经常会有需要引用第三方js的时候出现,自己查了很多资料都没有一个很好的处理办法,偶然发现了一个一次引用能同时调用多个function的方法,仅供参考。
查阅了一些资料发现大多数引用都是通过在对应.vue文件内的<script></script>标签里添加
import {test} from '../assets/js/temp.js'
的方式在调用外部的js,并且外部的js是这么定义的
function test(){
console.log("done")
}
export {
test
}
同时在.vue文件的methods:{}内部如下定义并使用
clicktest:function(){
test();
}
在<template></template>中使用<div @click="clicktest()">print in console with test</div>触发即可
但是这样只能一个js调用一个函数,未免太过于。。。。。
这是可以包含多个函数的js
var temp = {
test:function(){
console.log("test")
},
testA:function(){
console.log("testA")
}
}
export {
temp
}
并且在.vue文件里这样import
import {temp} from '../assets/js/temp.js'
在methods里这样定义
methods:{
test:function(){
temp.test();
},
testA:function(){
temp.testA();
}
}
就可以实现正常在一个js里调用多个函数了,但是如何调用类似layer.js或者模块类型的第三方js还没有成功,样例仅供参考,不足之处请指正