vscode扩展装的volar,vue3 support,我通过npm安装vue的一些插件,然后在vue文件中import,在使用时没有代码提示。以threejs为例,import后无法通过new THREE.的方式获取threejs的API,必须对着文档手动敲,我想知道这是特性还是缺了配置或插件?
<template>
<!-- <HelloWorld msg="You did it!" /> -->
<div ref="webgl" class="content"></div>
</template>
<script setup lang="ts">
import { onMounted, onUpdated, ref } from "vue";
import HelloWorld from "./components/HelloWorld.vue";
import * as THREE from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
//引入性能监视器stats.js
import Stats from 'three/addons/libs/stats.module.js';
const camera = new THREE.PerspectiveCamera(
90,
window.innerWidth / window.innerHeight,
0.01,
1000
);
camera.position.z = 1;
const scene = new THREE.Scene();
const vertices = new Float32Array([
0, 0, 0, //顶点1坐标
50, 0, 0, //顶点2坐标
0, 100, 0, //顶点3坐标
0, 0, 10, //顶点4坐标
0, 0, 100, //顶点5坐标
50, 0, 10, //顶点6坐标
]);
const attribue = new THREE.BufferAttribute(vertices, 3);
const geometry = new THREE.BufferGeometry();
geometry.attributes.position = attribue;
const material = new THREE.LineBasicMaterial({
color: 0xffff00,
size: 10.0 //点对象像素尺寸
});
const mesh = new THREE.LineSegments(geometry, material);
scene.add(mesh);
camera.lookAt(mesh)
const render = new THREE.WebGLRenderer({ antialias: true });
render.setSize(800, 600);
render.render(scene, camera);
render.setAnimationLoop();
const directionalLight = new THREE.DirectionalLight(0xffefff, 1);
// 设置光源的方向:通过光源position属性和目标指向对象的position属性计算
directionalLight.position.set(80, 100, 50);
// 方向光指向对象网格模型mesh,可以不设置,默认的位置是0,0,0
directionalLight.target = mesh;
scene.add(directionalLight);
const ambient = new THREE.AmbientLight(0xffffcb, 0.4);
scene.add(ambient);
const dirLightHelper = new THREE.DirectionalLightHelper(directionalLight, 5, 0xffffe);
scene.add(dirLightHelper);
const controls = new OrbitControls(camera, render.domElement);
const stats = new Stats();
stats.setMode(1)
// 如果OrbitControls改变了相机参数,重新调用渲染器渲染三维场景
controls.addEventListener("change", () => {
render.render(scene, camera); //执行渲染操作
}); //监听鼠标、键盘事件
let webgl = ref();
onMounted(() => {
console.log(webgl.value);
controls.enableDamping = true;
// document.body.appendChild(render.domElement)
webgl.value.appendChild(render.domElement);
webgl.value.appendChild(stats.domElement);
rendered();
});
const rendered = () => {
// mesh.rotation.y += 0.01;
render.render(scene, camera);
stats.update();
requestAnimationFrame(rendered);
};
</script>
<style>
.content {
margin: 50px 50px;
}
</style>