es6导入导出语法
test.js
let name1 = 'testName';
function testFunc(){
console.log(name1);
}
export default { name1, testFunc}
使用
<script>
// 导入
import test from '../test.js'
export default {
data() {
return {
// 使用
name: test.name1
}
},
methods:{
clickFunc(){
this.name = 'sszw'
// 使用
test.testFunc()
}
},
props:["msg"]
}
</script>
补充
如果一个包下有一个名为index.js 的文件,可以只导入到包这一层
import test from './testjs'
index.js 可以省略