vue中引入全局变量

1.main.js中代码

这里以引入three.js为例。

import * as THREE from 'three'
Vue.prototype.THREE = THREE

利用Vue.prototype来注册全局变量

2.引用

 this.scene = new this.THREE.Scene()

在组件中直接使用this.THREE来调用

你可能感兴趣的:(前端)