delowardev / vue3-circle-progress

Highly customizable & lightweight circular progressbar component for Vue 3, built with SVG and extensively customizable
https://codesandbox.io/s/determined-dawn-3ybev?file=/src/App.vue
MIT License
36 stars 14 forks source link

How update percent value #9

Closed Fabszn closed 2 years ago

Fabszn commented 2 years ago

Hello

I little bit confused.. I am using vue3-circle-progress component in my app. I didn't find a way to update percent value dynamically.

It seems that in documentation no information about this feature.

Could you have any advice to share.

Many thanks.

Kind regards

delowardev commented 2 years ago

Hi @Fabszn,

You can define the percentage value in your component & pass it to the vue3-circle-progress, example:

<CircleProgress :percent="percent" :viewport="true" :show-percent="true" />

  setup() {
    const percent = ref(75);

    // update percentage value
    onMounted(() => {
      setInterval(() => {
        if (percent.value === 25) {
          percent.value = 75;
        } else {
          percent.value = 25;
        }
      }, 1000);
    });

    return {
      percent,
    };
  }

Here is the live example: https://codesandbox.io/s/determined-dawn-3ybev?file=/src/App.vue:39-114

Fabszn commented 2 years ago

Many thanks for you quick answer. I looked at your example, but probably I am to newbe with vueJS... but what ref(75) means ? I tried to implement as your example, but I got error message that value is on readonly mode.

Many thanks for your help,

delowardev commented 2 years ago

Here ref(75) means, I set a default initial value of 75. Please check the ref documentation here: https://vuejs.org/api/reactivity-core.html#ref

Fabszn commented 2 years ago

Many thanks for your answer.. I dive into it :)

Fabszn commented 2 years ago

It works fine ! Thanks...