vue 实现标签云效果 全码

vue实现标签云<template> <div class="tagcloud-all" ref="tagcloudall" @click="infClick"> <a v-for="(item, index) in tagList" :key="index" class = "judge" rel="external nofollow" :style="'color:' + item.color +
摘要由CSDN通过智能技术生成

vue实现标签云

在这里插入图片描述

<template>
  <div class="tagcloud-all" ref="tagcloudall" @click="infClick">
    <a
      v-for="(item, index) in tagList"
      :key="index"
      class = "judge"
      rel="external nofollow"
      :style="'color:' + item.color + ';top: 0;left: 0;filter:none;'"
      >{
   {
    item.name }}</a
    >
  </div>
</template>

<script>
import {
   getClour} from '@/api/campus/index.js'
export default {
   
    mounted(){
   
        // console.log(this.$emit(custom,22222222222222))
        // getClour().then(data => {
   
        //     console.log(data)
        // })
    },
data() {
   
    return {
   
      tagList: [],
      radius: 250,
      dtr: Math.PI / 180,
      d: 300,
      mcList: [],
      active: false,
      lasta: 1,
      lastb: 1,
      distr: true,
      tspeed: 10,
      size: 250,
      mouseX: 0,
      mouseY: 0,
      howElliptical: 1,
      oList: null,
      oA: null,
      sa: 0,
      ca: 0,
      sb: 0,
      cb: 0,
      sc: 0,
      cc: 0
    }
    
},
methods: {
   
    infClick(e){
   
        if(e.target.className == "judge"){
   
            // console.log(e.target.className)
            this.$emit('custom',e.target.innerHTML)
        }
    },
    // 生成随机数
    getRandomNum() {
   
      return Math.floor(Math.random() * (255 + 1));
    },
    // 三角函数角度计算
    sineCosine(a, b, c) {
   
      this.sa = Math.sin(a * this.dtr);
      this.ca = Math.cos(a * this.dtr);
      this.sb = Math.sin(b * this.dtr);
      this.cb = Math.cos(b * this.dtr);
      this.sc = Math.sin(c * this.dtr);
      this.cc = Math.cos(c * this.dtr);
    },
    // 设置初始定位
    positionAll() {
   
      this.$nextTick(() => {
         // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染
        var phi = 0;
        var theta = 0;
        var max = this.mcList.length;
        var aTmp = [];
        var oFragment = document.createDocumentFragment();
        // 随机排序
        for (let i = 0; i < this.tagList.length; i++) {
   
          aTmp.push(this.oA[i]);
        }
        aTmp.sort(() => {
   
          return Math.random() < 0.5 ? 1 : -1;
        });
        for (let i = 0; i < aTmp.length; i++) {
   
          oFragment.appendChild(aTmp[i]);
        }
        this.oList.appendChild(oFragment);
        for (let i = 1; i < max + 1; i++) {
   
          if (this.distr) {
   
            phi = Math.acos(-1 + (2 * i - 1) / max);
            theta = Math.sqrt(max * Math.PI) * phi;
          } else {
   
            phi = Math.random() * (Math.PI);
            theta = Math.random() * (2 * Math.PI);
          }
          // 坐标变换
          this.mcList[i - 1].cx = this.radius * Math.cos(theta) * Math.sin(phi)
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值