Giter Club home page Giter Club logo

Comments (2)

shzlw avatar shzlw commented on June 2, 2024

是的,是需要wrap一下,我看了下Vue的文档,自己试了wrap一个控件,可以运行,你可以试试哈。

"dependencies": {
  "vue": "^2.5.2",
  "vue-router": "^3.0.1",
  "zeu": "^1.1.1"
},

TextMeter.vue

<template>
  <canvas :id="id" :width="width" :height="height"></canvas>
</template>

<script>
import * as zeu from 'zeu';
export default {
  name: 'TextMeter',
  props: {
    id: String,
    width: Number,
    height: Number,
    options: Object,
    displayValue: String,
    value: Number
  },
  mounted() {
    if (!this.chart) {
      this.init();
    }
  },
  watch: {
    displayValue(val) {
      this.chart.displayValue = val;
    },
    value(val) {
      this.chart.value = val;
    }
  },
  beforeDestroy() {
    this.destory();
  },
  methods: {
    init() {
      let textMeter = new zeu.TextMeter(this.$el.id, this.options);
      textMeter.displayValue = this.displayValue;
      textMeter.value = this.value;
      this.chart = textMeter;
    },
    destory() {
      this.chart.destroy();
      this.chart = null;
    }
  }
}
</script>
</script>

TestPage.vue

<template>
   <div>
     <button @click="update">Update</button>
     <TextMeter :id="textMeter.id" :width="textMeter.width" :height="textMeter.height" 
      :displayValue="displayValue" :value="value" :options="textMeter.options"></TextMeter>
   </div>
</template>

<script>
import TextMeter from './TextMeter';

export default {
  name: 'TestPage',
  components: {
    TextMeter
  },
  data () {
    return {
      textMeter: {
        id: 'test',
        width: 200,
        height: 100,
        options: {}
      },
      displayValue: 'ZEU',
      value: 80
    }
  },
  methods: {
    update() {
      this.displayValue = 'NEW';
      this.value = 30;
    }
  }
}
</script>

from zeu.

zhou-wjjw avatar zhou-wjjw commented on June 2, 2024

谢谢大佬,学到了,很不错

from zeu.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.