开发中发现的小技巧

1.利用Echart作一个词云
为了减少消耗和可复用性,将其封装成一个组件
EChart_wordcloud.vue

<template>
  <div :style="{height:height,width:width}" />
</template>
<script>
import * as echarts from 'echarts';
import "echarts-wordcloud";
// echarts theme
require('echarts/theme/macarons');
export default {
  // mixins: [resize],
  props: {
    type: {
      type: String,
      default: '1',
    },
    width: {
      type: String,
      default: '100%',
    },
    height: {
      type: String,
      default: '345px',
    },
    autoResize: {
      type: Boolean,
      default: true,
    },
    chartData: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val);
      },
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons');
      this.setOptions(this.chartData);
    },
    setOptions(val) {
      this.chart.setOption({
        // tooltip: {
        //     show: true,
        //     pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>',
        //     formatter: '{b}:{c} 热度',
        //     textStyle: {
        //     fontSize: 28           
        //     },
        //     backgroundColor: null,
        //     borderWidth:null,
        //   },
        series: [
          {
            type: "wordCloud",
            //用来调整词之间的距离
            gridSize: 10,
            //用来调整字的大小范围
            // Text size range which the value in data will be mapped to.
            // Default to have minimum 12px and maximum 60px size.
            sizeRange: [14, 60],
            // Text rotation range and step in degree. Text will be rotated randomly in range [-90,                                                                             90] by rotationStep 45
            //用来调整词的旋转方向,,[0,0]--代表着没有角度,也就是词为水平方向,需要设置角度参考注释内容
            // rotationRange: [-45, 0, 45, 90],
            // rotationRange: [ 0,90],
            rotationRange: [0, 0],
            //随机生成字体颜色
            // maskImage: maskImage,
            textStyle: {
              color: function () {
                return (
                  "rgb(" +
                  Math.round(Math.random() * 255) +
                  ", " +
                  Math.round(Math.random() * 255) +
                  ", " +
                  Math.round(Math.random() * 255) +
                  ")"
                );
              },
            },
            //位置相关设置
            // Folllowing left/top/width/height/right/bottom are used for positioning the word cloud
            // Default to be put in the center and has 75% x 80% size.
            left: "center",
            top: "center",
            right: null,
            bottom: null,
            width: "200%",
            height: "200%",
            //数据
            data: val,
          }
        ],
      })
    },
  },
};
</script>

在需要使用到词云的地方导入并添加组件标签

import EChartWordcloud from '@/components/EChart/EChart_wordcloud.vue'

<e-chart-wordcloud  :chart-data="eChartData8"/>
export default {
  components:{
   EChartWordcloud
  },
data() {
    return {
 
      eChartData8:[{
                        name: "审批",
                        value: 2500
                    },
                    {
                        name: "佣金",
                        value: 2300
                    },
                    {
                        name: "发票",
                        value: 2000
                    },

      ],
      }
    }

2. Ant Design Vue 的表单组件自定义一行序号呈现自增顺序(分页后也与前一页联系而不是相同)

   <a-table :data-source="listdata" :pagination="pagination" :loading="loading" @change="pageChange" :columns="columns" >
export default {
  data() {
    return {
      columns:[
        {
          title:'序号',
          align:'center',
          customRender: (text, record, index) => `${(this.param.pageNo - 1) *this.param.pageSize + index + 1}`,
        },
        {
          title:'名称',
          key: 'title',
          dataIndex:'title',
          align:'center',
          ellipsis:'true'
        },
      ],
      param: {
        pageNo: 1,
        pageSize: 10
      },
      pagination: {
        total: 0,
        pageSize: 10,//每页中显示10条数据
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ["10", "20", "50", "100"],//每页中显示的数据
        showTotal: total => `共有 ${total} 条数据`,  //分页中显示总的数据
      },
      listdata: [],
      loading: false,
      total: '',
    };
  },

    pageChange(pagination) {
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.param.pageNo = pagination.current;
      this.param.pageSize = pagination.pageSize;
      this.getPaperList()
    },
  },
}

this.param.pageNo和this.param.pageSize是自己所定义的所在页数和每页展示的数量。
3.设置背景图片周围有空白、铺不满
vue项目中有时设置背景图片会出现图片周围都有空白的情况,有可能是body、html的默认样式的原因。
如果我们直接将背景图片在body设置,就会造成vue项目的样式的污染,所以必须使用其他方法。
我们可以在当前组件或者App.vue中在组件的最外层添加一个div标签并且把背景图片赋给该div标签的样式
blog.csdnimg.cn/89dcd5f7d3fd419f947cb0af5100cfd2.png)

.bj{ background:#1d2989 url('~@/assets/index20220218_06.jpg') center center no-repeat;}![

4.前端接收到的数据内容有问题
前端从后端接收到的数据展示到页面时有时数据内容有很多不合理的空白还有图片(变成了连接)所以需要去除掉这些信息。通过正则表达式

replace(/\s*/g,'') //去除空格
replace(/<\/?.+?\/?>/g,'')//去除标签
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Unity开发,有一些小技巧可以提高效率和方便开发。以下是一些常用的Unity开发技巧: 1. 锁定角度和移动对象:在旋转对象时按住Ctrl/Cmd键可以锁定角度,同样的方法也适用于移动对象。要修改锁定的默认值,可以到Edit->SnapSettings进行修改。 2. 对齐锁定技巧:当移动对象时,按住V键可以启用节点锁定,可以将两个点简单对齐,对于关卡对象排列有帮助。 3. 直接开启说明文件:在组件选单内点击蓝色的问号图标,可以直接打开说明文件。 4. 在Play模式下修改数值:如果在Play模式下调整数值后发现不合适,可以点击组件列表右上方的小齿轮,然后选择CopyComponent将组件复制一份,在退出Play模式后再点击小齿轮选择PasteComponent将复制的组件粘贴回去。 5. 使用Layers按钮管理显示或隐藏对象:使用Layers按钮可以管理显示或隐藏对象。例如,可以将一些只在编辑初期使用的坐标对象归类到一个Layer,当要隐藏这些对象时,只需点击Layers按钮,然后将该图层右边的眼睛图标取消勾选即可。 6. 在Profiler切换图表显示:在Profiler,可以点击Drawcalls、Scripts、Rendering、VSync等名称左边的小方块来切换是否显示相应图表。 7. 调整Playmode tint颜色:初学者在Play模式下修改东西后,可能在停止播放后发现所有的修改都恢复到调整前。为了避免这种困扰,可以在Preferences设置的Colours/Colors调整Playmode tint颜色,这样你就可以很容易地分辨是否在播放模式。 这些小技巧可以帮助开发者更高效地使用Unity进行开发和调试。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Unity 开发的十个实用小技巧](https://blog.csdn.net/weixin_46052359/article/details/115072925)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值