gpt4 book ai didi

vue.js - Particles.js 到 Vue 组件

转载 作者:搜寻专家 更新时间:2023-10-30 22:21:34 25 4
gpt4 key购买 nike

我正在尝试适应 particles.js到下面示例中的 Vue.js 组件: https://codepen.io/MichaelVanDenBerg/pen/WpXGRm

但是,当使用下面的代码时,我在控制台中收到以下错误消息:

[Vue warn]: Error in mounted hook: "TypeError: this.particles is not a function"

如何在下面的代码中修复它?

模板:

</template>
<div>
<div id="particles-js"></div>
</div>
</template>

脚本:

<script>
import particles from 'particles.js'
export default {
mounted() {
this.initParticles()
},
methods: {
initParticles () {
particles("particles-js", {
"particles": {
"number": {
"value": 80,
"density": {
"enable": true,
"value_area": 700
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 6,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": true,
"mode": "grab"
},
"onclick": {
"enable": true,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 140,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
})
}
}
}
</script>

CSS:

<style scoped>
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background: #00356B;
}
</style>

最佳答案

particles.js package不导出任何东西,而是它 sets window.particlesJS .

要使用这个包,只需将它导入您的脚本,然后调用 particlesJS():

import 'particles.js'
export default {
// ...
methods: {
initParticles() {
window.particlesJS('particles-js', {/* ... */})
}
}
}

demo

关于vue.js - Particles.js 到 Vue 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50341821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com