Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with vue 3? #248

Open
atif0075 opened this issue Dec 7, 2022 · 4 comments
Open

Integration with vue 3? #248

atif0075 opened this issue Dec 7, 2022 · 4 comments

Comments

@atif0075
Copy link

atif0075 commented Dec 7, 2022

Hi, how can I use it in vue 3 project?

@maxwellito
Copy link
Owner

Hi, I don't know how Vue 3 works. But I guess you need to access the DOM element you want to manipulate

@rangeldor
Copy link

rangeldor commented Feb 9, 2023

<template>
  <svg
    id="animate-icon-dlavro"
    xmlns="http://www.w3.org/2000/svg"
    viewBox="0 0 368.5 66.62"
  >
    <g data-name="Camada 2">
      <g
        id="Camada_1-2"
        data-name="Camada 1"
      ><path
        :fill="st1Fill"
        :stroke="st1Stroke"
        class="cls-1"
        d="M59.72,35.42a.78.78,0,0,0-.39-.69c-1.11-.65-4.73-2.35-12.13-2.35-8.79,0-28.67,5.53-46.69,31.09a2,2,0,0,0,1.62,3.15H25.58C34.57,66.62,59.46,63.22,59.72,35.42Z"
      />
...
      </g>
    </g>
  </svg>
</template>

<script lang="ts" setup>
import Vivus from 'vivus'
import { ref, onMounted, computed, toRefs } from 'vue'

interface Props {
  animate?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  animate: true
})

const { animate } = toRefs(props)

const isStroke = ref<boolean>(false)
const isFill = ref<boolean>(false)

const st1Fill = computed(() => {
  return isFill.value ? '#43807A' : 'rgb(255,255,255)'
})

const st1Stroke = computed(() => {
  return isStroke.value ? 'rgb(255,255,255)' : '#43807A'
})

const st2Fill = computed(() => {
  return isFill.value ? '#2D2D2D' : 'rgb(255,255,255)'
})

const st2Stroke = computed(() => {
  return isStroke.value ? 'rgb(255,255,255)' : '#2D2D2D'
})

onMounted(() => {
  if (animate.value) {
    const icon = new Vivus('animate-icon-dlavro', {
      type: 'delayed',
      duration: 150,
      animTimingFunction: Vivus.EASE
    })

    icon.play(() => {
      isFill.value = true
      isStroke.value = true
    // called after the animation completes
    })
  } else {
    isFill.value = true
    isStroke.value = true
  }
})
</script>

<style scoped>
.cls-3 {
  fill: v-bind(st2Fill);
  stroke: v-bind(st2Stroke);
}
</style>

I have a vue component that is an icon.

I hope I could have helped :)

@erikacamilleri
Copy link

Hi, sorry if this is too basic, I have a Vue3 project but the import is not working for me:

import Vivus from vivus with an npm insall. I see it included in the dependencies, but it cannot recognise 'vivus'. I never had this probem before. Not sure how to debug this.

@kostikovk
Copy link

@erikacamilleri I hope you're talking about the TS issue and you need to install types dep

npm install @types/vivus -D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants