温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

vue3中怎么使用particles插件实现粒子背景

发布时间:2022-03-31 17:06:08 阅读:1478 作者:iii 栏目:开发技术
Vue开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这篇文章主要介绍了vue3中怎么使用particles插件实现粒子背景的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇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: {
				fpsLimit50,
				interactivity: {
					events: {
						onClick: {
							enabletrue,
							mode'push'
						},
						onHover: {
							enabletrue,
							mode'grab'
						},
						resizetrue
					},
					modes: {
						bubble: {
							distance400,
							duration2,
							opacity0.6,
							size10
						},
						push: {
							quantity4
						},
						repulse: {
							distance200,
							duration0.4
						}
					}
				},
				particles: {
					color: {
						value'#ffffff'
					},
					links: {
						color'#ffffff',
						distance150,
						enabletrue,
						opacity0.5,
						width1
					},
					collisions: {
						enabletrue
					},
					move: {
						direction'none',
						enabletrue,
						outMode'bounce',
						randomfalse,
						speed2,
						straightfalse
					},
					number: {
						density: {
							enabletrue,
							value_area800
						},
						value60
					},
					opacity: {
						value0.5
					},
					shape: {
						type'circle'
					},
					size: {
						randomtrue,
						value3
					}
				},
				detectRetinatrue
			}
		})
 
		return {
			...toRefs(data),
		}
	}
}
</script>

 3.1、script setup下页面使用

<script setup>
import { reactive, toRefs } from "vue";
 
const data reactive({
    options: {
        fpsLimit50,
        interactivity: {
            events: {
                onClick: {
                    enabletrue,
                    mode"push",
                },
                onHover: {
                    enabletrue,
                    mode"grab",
                },
                resizetrue,
            },
            modes: {
                bubble: {
                    distance400,
                    duration2,
                    opacity0.6,
                    size10,
                },
                push: {
                    quantity4,
                },
                repulse: {
                    distance200,
                    duration0.4,
                },
            },
        },
        particles: {
            color: {
                value"#ffffff",
            },
            links: {
                color"#ffffff",
                distance150,
                enabletrue,
                opacity0.5,
                width1,
            },
            collisions: {
                enabletrue,
            },
            move: {
                direction"none",
                enabletrue,
                outMode"bounce",
                randomfalse,
                speed2,
                straightfalse,
            },
            number: {
                density: {
                    enabletrue,
                    value_area800,
                },
                value60,
            },
            opacity: {
                value0.5,
            },
            shape: {
                type"circle",
            },
            size: {
                randomtrue,
                value3,
            },
        },
        detectRetinatrue,
    },
})
 
const { options } = toRefs(data) // 直接解构出来,页面上就不用data.options了
</script>

关于“vue3中怎么使用particles插件实现粒子背景”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“vue3中怎么使用particles插件实现粒子背景”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×