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来调用

发布了25 篇原创文章 · 获赞 1 · 访问量 1636

猜你喜欢

转载自blog.csdn.net/weixin_43977647/article/details/104500587
今日推荐