es6导入导出语法

image
image
image

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 可以省略

本文作者:Sherwin

本文链接:https://www.cnblogs.com/sherwin1995/p/16851528.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Sherwin_szw  阅读(35)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.