vue3使用particles插件實現(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、頁面使用
<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) // 直接解構(gòu)出來,頁面上就不用data.options了
</script>總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
Vue利用路由鉤子token過期后跳轉(zhuǎn)到登錄頁的實例
下面小編就為大家?guī)硪黄猇ue利用路由鉤子token過期后跳轉(zhuǎn)到登錄頁的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10
在Vue中實現(xiàn)網(wǎng)頁截圖與截屏功能詳解
在Web開發(fā)中,有時候需要對網(wǎng)頁進行截圖或截屏,Vue作為一個流行的JavaScript框架,提供了一些工具和庫,可以方便地實現(xiàn)網(wǎng)頁截圖和截屏功能,本文將介紹如何在Vue中進行網(wǎng)頁截圖和截屏,需要的朋友可以參考下2023-06-06
淺談vue中使用編輯器vue-quill-editor踩過的坑
這篇文章主要介紹了淺談vue中使用編輯器vue-quill-editor踩過的坑,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08
Vue2實現(xiàn)圖片的拖拽,縮放和旋轉(zhuǎn)效果的示例代碼
這篇文章主要為大家介紹了如何基于vue2?實現(xiàn)圖片的拖拽、旋轉(zhuǎn)、鼠標滾動放大縮小等功能。文中的示例代碼講解詳細,感興趣的小伙伴可以嘗試一下2022-11-11
使用vue-router與v-if實現(xiàn)tab切換遇到的問題及解決方法
這篇文章主要介紹了vue-router與v-if實現(xiàn)tab切換的思考,需要的朋友可以參考下2018-09-09
Vue +WebSocket + WaveSurferJS 實現(xiàn)H5聊天對話交互的實例
這篇文章主要介紹了Vue +WebSocket + WaveSurferJS 實現(xiàn)H5聊天對話交互的實例,幫助大家更好的理解和學(xué)習(xí)vue,感興趣的朋友可以了解下2020-11-11

