大屏组件dataV使用踩坑记录

 绑定key并在窗口大小改变后更改,避免更改配置后视图不更新,this.conf = { ...this.conf }也是避免视图不更新的。

<template>
  <div class="text-wrapper" :class="'text-line'" :style="config.style">
    <dv-percent-pond ref="chart" :key="key" :config="conf" :style="{width:config.style.width+'px',height:config.style.height+'px'}" />
  </div>
</template>

<script>
export default {
  name: 'PercentPond',
  props: {
    config: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      conf: {
        value: 0
      },
      key: 1
    }
  },
  computed: {
    tipsStyle() {
      return Object.assign({
        lineHeight: this.config.style.height - Number(this.config.style.borderWidth ? this.config.style.borderWidth.replace('px', '') : 0) * 2 - 10 + 'px'
      }, this.config.style)
    },
    style() {
      const style = {}
      if (Number(this.config.style.underline)) {
        style.textDecoration = 'underline'
      }
      if (this.config.style.fontSize) {
        style.fontSize = this.config.style.fontSize + 'px'
      }
      if (Number(this.config.style.weight)) {
        style.fontWeight = 'bold'
      }
      if (Number(this.config.style.style)) {
        style.fontStyle = 'italic'
      }
      if (Number(this.config.style.center)) {
        style.textAlign = 'center'
      }
      if (Number(this.config.style.verticalAlign)) {
        style.verticalAlign = 'middle'
      }
      return style
    }
  },
  watch: {
    'config': {
      handler() {
        this.change()
      },
      deep: true
    }
  },
  created() {
  },
  mounted() {
    this.change()
  },
  beforeDestroy() {
  },
  methods: {
    change() {
      if (this.config && this.config.params && this.config.params.result) {
        this.$set(this.conf, 'value', Number(this.config.params.result))
        this.conf = { ...this.conf }
        // 进度池配色
        if (this.config.style.startColor || this.config.style.endColor) {
          this.conf.colors = [this.config.style.startColor, this.config.style.endColor]
        } else {
          this.conf.colors = ['#3DE7C9', '#00BAFF']
        }
      }
      const that = this
      window.addEventListener('resize', function(e) {
        that.$nextTick(() => {
          that.key++
        })
      })

      // 此处为官网推荐更新数据方式
      /**
         状态更新
         避免你的组件更新了数据后,状态却不刷新,也就是没变化,请务必看这里
         组件props均未设置deep监听,刷新props时,请直接生成新的props对象(基础数据类型除外)
         ,或完
         成赋值操作后使用ES6拓展运算符生成新的props对象
         (this.someProps = { ...this.someProps })。
         **/
      // console.log(this.conf.colors, this.config.style)
    }
  }
}
</script>

<style scoped>
  .text-wrapper {
    width: 100%;
    height: 100%;
    display: table;
  }
  .text-body {
    display: table-cell;
  }
  .text-no-line {
    white-space:nowrap;
  }
  .text-line {
    word-break: break-all;
    word-wrap: break-word;
  }
  .text-wrapper p {
    margin: 0;
  }
  .text-tip {
    color: #888;
    width: 100%;
    height: 100%;
    text-align: center;
  }
  .over-hide {
    overflow: hidden;
  }
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3 中使用大屏数据可视化库 DataV 的步骤如下: 1. 首先,确保你已经在项目中安装了 Vue 3 及其相应的依赖。可以使用 Vue CLI 或其他工具来初始化项目并生成基础的目录结构和配置文件。 2. 在你的前端项目中,使用 npm 或 yarn 安装 DataV 插件。 可以使用以下命令进行安装: ``` npm install @jiaminghi/data-view ``` 或 ``` yarn add @jiaminghi/data-view ``` 3. 在你的 Vue 组件中引入 DataV 插件并使用它。 在你的组件中,使用 import 语句将 DataV 引入: ``` import DataV from '@jiaminghi/data-view' ``` 然后,在你的模板中使用 DataV 的组件来展示大屏数据可视化: ``` <template> <dataVComponent></dataVComponent> </template> ``` 4. 根据 DataV 的文档和示例,按照你的需求来配置和使用 DataV 的组件和功能。可以参考 DataV 的官方文档和示例代码来了解如何使用不同的组件和功能来展示大屏数据可视化效果。 如果你在使用 TypeScript 进行开发,还需要在 `shims-vue.d.ts` 文件中添加以下声明,以便让 TypeScript 识别 DataV 的模块: ``` declare module '@jiaminghi/data-view' ``` 这样 TypeScript 就能正确地识别并使用 DataV 的模块。 总结: 1. 确保项目中安装了 Vue 3 及其依赖。 2. 使用 npm 或 yarn 安装 DataV 插件。 3. 在 Vue 组件中引入 DataV 插件。 4. 配置和使用 DataV 的组件和功能来展示大屏数据可视化效果。 请根据你的具体需求和项目情况进行相应的配置和使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [vue3使用大屏dataV详细教程](https://blog.csdn.net/weixin_51958960/article/details/128873162)[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: 50%"] - *2* [vue整合SSM项目实战](https://download.csdn.net/download/m0_55755339/88241603)[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: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值