vue3使用particles插件實(shí)現(xiàn)粒子背景的方法詳解
效果(可以修改多種不同的樣式效果)

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、頁(yè)面使用
<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下頁(yè)面使用
<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) // 直接解構(gòu)出來(lái),頁(yè)面上就不用data.options了
</script>總結(jié)
本篇文章就到這里了,希望能夠給你帶來(lái)幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
Vue3新特性Suspense和Teleport應(yīng)用場(chǎng)景分析
本文介紹了Vue2和Vue3中的Suspense用于處理異步請(qǐng)求的加載提示,以及如何在組件間實(shí)現(xiàn)動(dòng)態(tài)加載,同時(shí),Teleport技術(shù)展示了如何在DOM中靈活地控制組件的渲染位置,解決布局問(wèn)題,感興趣的朋友跟隨小編一起看看吧2024-07-07
Vue+ElementUI實(shí)現(xiàn)從后臺(tái)動(dòng)態(tài)填充下拉框的示例代碼
本文主要介紹了Vue+ElementUI實(shí)現(xiàn)從后臺(tái)動(dòng)態(tài)填充下拉框的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
Vue3中從一個(gè)頁(yè)面(index)傳輸數(shù)值到另一個(gè)頁(yè)面(form)的方法詳解
在 Vue 3 開發(fā)中,經(jīng)常需要在不同組件或頁(yè)面之間傳遞數(shù)據(jù),例如從 index 頁(yè)面獲取某個(gè)數(shù)值(如 cntr、tradeId)后,將其傳輸?shù)?nbsp;form 頁(yè)面進(jìn)行填寫或編輯,本文將介紹幾種常見的數(shù)據(jù)傳輸方法,并為每種方法提供一個(gè)小的 Demo 代碼示例,需要的朋友可以參考下2025-02-02
vue vite之LogicFlow安裝核心依賴及項(xiàng)目初始化詳解
這篇文章主要為大家介紹了vue vite之LogicFlow安裝核心依賴及項(xiàng)目初始化詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
vue項(xiàng)目啟動(dòng)命令個(gè)人學(xué)習(xí)記錄
最近想要學(xué)習(xí)vue,正好看到資料,如何通過(guò)命令創(chuàng)建vue項(xiàng)目的方法,就留個(gè)筆記,下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目啟動(dòng)命令的相關(guān)資料,需要的朋友可以參考下2023-02-02
Vuex中g(shù)etters和actions的使用補(bǔ)充說(shuō)明
這篇文章主要介紹了在Vuex中關(guān)于getters和actions使用的補(bǔ)充作了簡(jiǎn)要說(shuō)明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2021-09-09
vue項(xiàng)目本地開發(fā)使用Nginx配置代理后端接口問(wèn)題
這篇文章主要介紹了vue項(xiàng)目本地開發(fā)使用Nginx配置代理后端接口問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
Vue使用el-table實(shí)現(xiàn)自適應(yīng)列寬
這篇文章主要為大家詳細(xì)介紹了Vue使用el-table實(shí)現(xiàn)自適應(yīng)列寬,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01

