简体   繁体   English

在 vue.js/nuxt.js 中使用 three.js 库客户端

[英]Using three.js library client-side in vue.js/nuxt.js

I am trying to use the three.js library (installed with npm) to render 3D models on the client side in my nuxt.js app, but I'm running out of ideas to get the import to work (I didn't have many to begin with).我正在尝试使用 three.js 库(与 npm 一起安装)在我的 nuxt.js 应用程序的客户端渲染 3D 模型,但我已经没有什么想法可以开始导入工作了( )。 Each time I get an error related to three not being defined.每次我收到与三个未定义相关的错误时。 Here is what I have tried:这是我尝试过的:

In nuxt.config.jsnuxt.config.js

plugins: [
    {src: "~/plugins/three", mode: "client"}
  ]

In plugins/three.jsplugins/three.js

import Vue from 'vue'
import * as THREE from 'three'

Vue.use(THREE);

In component that I'm trying to use it in:在我尝试使用它的组件中:

if(process.client) {
    require('three');
    require('three-obj-loader');
    require('three-obj-mtl-loader');
    require('three-orbitcontrols');
}

Calling from within functions as THREE.someFunction()从函数内部调用THREE.someFunction()

I imported three in my nuxt app recently successfully, even though i'm not checking if it is client side.我最近在我的 nuxt 应用程序中成功导入了三个,即使我没有检查它是否是客户端。

From what i can see you import like this: import * as Three from `three` but then you are calling it with three and not Three .从我可以看到你像这样导入: import * as Three from `three`但是你用three而不是Three来调用它。 It's case sensitive!它区分大小写!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM