日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

Vue里引入three.js

發布時間:2025/3/12 vue 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vue里引入three.js 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近因為three.js的項目要用Vue.js 來重構,所以不太清楚在Vue里面怎么引入。找了很多方法都是一直報錯,最后在Stack Overflow找到了。

首先是下載包,直接用?npm install three --save 就行了。

然后就是在component里面引入。

<template><div><div id="container"></div></div> </template><script> import * as Three from 'three'export default {name: 'ThreeTest',data() {return {camera: null,scene: null,renderer: null,mesh: null}},methods: {init: function() {let container = document.getElementById('container');this.camera = new Three.PerspectiveCamera(70, container.clientWidth/container.clientHeight, 0.01, 10);this.camera.position.z = 1;this.scene = new Three.Scene();let geometry = new Three.BoxGeometry(0.2, 0.2, 0.2);let material = new Three.MeshNormalMaterial();this.mesh = new Three.Mesh(geometry, material);this.scene.add(this.mesh);this.renderer = new Three.WebGLRenderer({antialias: true});this.renderer.setSize(container.clientWidth, container.clientHeight);container.appendChild(this.renderer.domElement);},animate: function() {requestAnimationFrame(this.animate);this.mesh.rotation.x += 0.01;this.mesh.rotation.y += 0.02;this.renderer.render(this.scene, this.camera);}},mounted() {this.init();this.animate()} } </script> <style scoped>#container {height: 400px;} </style>

?

總結

以上是生活随笔為你收集整理的Vue里引入three.js的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。