Skip to content

When I use the Vue 3 Composition API, I find that the generated instance cannot be destroyed. However, in Vue 2, this is normal. #171

@heyu3913

Description

@heyu3913

Below is my code, and when I click the "Destroy!!!!!!!!" button, an error is reported in the console.

<template>
	<div id="login">
		<div ref="vantaRef" style="width: 100%; height: 90vh"></div>
		<button style="width: 200px;height: 20px" @click="test">Destory!!!!!!!!</button>
	</div>
</template>
<script setup>
import {ref, onBeforeUnmount, onMounted} from 'vue';
import * as THREE from "three";
import BIRDS from "vanta/src/vanta.birds";

const vantaRef = ref(null);
const vantaEffect = ref(null);
const vantaEffectStyle = ref(null);



onMounted(()=>{
	vantaEffect.value = BIRDS({
		el: vantaRef.value,
		THREE: THREE,
	});
	//样式
	vantaEffectStyle.value =  VANTA.BIRDS({
		el: vantaRef.value,
		/*以下为样式配置*/
		mouseControls: true,
		touchControls: true,
		gyroControls: false,
		minHeight: 200.0,
		minWidth: 200.0,
		scale: 1.0,
		scaleMobile: 1.0,
		color: 0xc7d1e8,
		backgroundColor: 0x400bb1,
		points: 13.0,
		maxDistance: 21.0,
		spacing: 16.0,
	});
})
onBeforeUnmount(() => {
	if(vantaEffect.value && vantaEffectStyle.value){
		vantaEffect.value.destroy()
		vantaEffectStyle.value.destroy()
	}
});
const test = ()=>{
	if(vantaEffect.value && vantaEffectStyle.value){
		vantaEffect.value.destroy()
		vantaEffectStyle.value.destroy()
	}
}


</script>
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions