您好,登錄后才能下訂單哦!
這篇文章主要介紹了vue3中怎么使用particles插件實現粒子背景的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇vue3中怎么使用particles插件實現粒子背景文章都會有所收獲,下面我們一起來看看吧。
效果(可以修改多種不同的樣式效果)
1、安裝
npm install particles.vue3
2、main.js
import { createApp } from 'vue' import App from './App.vue' import router from "./router"; import Particles from "particles.vue3"; // 引入 const app = createApp(App); app.use(router).use(Particles).mount("#app");
3、頁面使用
<template> <div class="box"> <Particles id="tsparticles" class="login-partic" :options="options" /> </div> </template> <script> import { reactive, toRefs } from "vue"; export default { setup(props) { const data = reactive({ options: { fpsLimit: 50, interactivity: { events: { onClick: { enable: true, mode: 'push' }, onHover: { enable: true, mode: 'grab' }, resize: true }, modes: { bubble: { distance: 400, duration: 2, opacity: 0.6, size: 10 }, push: { quantity: 4 }, repulse: { distance: 200, duration: 0.4 } } }, particles: { color: { value: '#ffffff' }, links: { color: '#ffffff', distance: 150, enable: true, opacity: 0.5, width: 1 }, collisions: { enable: true }, move: { direction: 'none', enable: true, outMode: 'bounce', random: false, speed: 2, straight: false }, number: { density: { enable: true, value_area: 800 }, value: 60 }, opacity: { value: 0.5 }, shape: { type: 'circle' }, size: { random: true, value: 3 } }, detectRetina: true } }) return { ...toRefs(data), } } } </script>
3.1、script setup下頁面使用
<script setup> import { reactive, toRefs } from "vue"; const data = reactive({ options: { fpsLimit: 50, interactivity: { events: { onClick: { enable: true, mode: "push", }, onHover: { enable: true, mode: "grab", }, resize: true, }, modes: { bubble: { distance: 400, duration: 2, opacity: 0.6, size: 10, }, push: { quantity: 4, }, repulse: { distance: 200, duration: 0.4, }, }, }, particles: { color: { value: "#ffffff", }, links: { color: "#ffffff", distance: 150, enable: true, opacity: 0.5, width: 1, }, collisions: { enable: true, }, move: { direction: "none", enable: true, outMode: "bounce", random: false, speed: 2, straight: false, }, number: { density: { enable: true, value_area: 800, }, value: 60, }, opacity: { value: 0.5, }, shape: { type: "circle", }, size: { random: true, value: 3, }, }, detectRetina: true, }, }) const { options } = toRefs(data) // 直接解構出來,頁面上就不用data.options了 </script>
關于“vue3中怎么使用particles插件實現粒子背景”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“vue3中怎么使用particles插件實現粒子背景”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。