-
Notifications
You must be signed in to change notification settings - Fork 133
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
useImage hook #253
Comments
Is it the last version of |
Yes, Oh, well, I finished working for today, I'll try again on monday. |
Apparently, after a couple of restart, the problem solved itself and now it's working. |
Hi, still me, sorry to bother, but is it possible to use it for dynamicly changing images? |
Like this: <template>
<div>
<!-- Toggle Button -->
<button @click="toggleImage">Toggle Image</button>
<!-- Konva Stage -->
<v-stage :config="stageSize">
<v-layer>
<!-- Display the Image -->
<v-image
v-if="currentImage"
:config="{
x: 100,
y: 100,
image: currentImage,
width: 200,
height: 200,
}"
/>
</v-layer>
</v-stage>
</div>
</template>
<script setup>
import { ref } from "vue";
import { useImage } from "vue-konva";
// Define stage size
const stageSize = {
width: window.innerWidth,
height: window.innerHeight,
};
// Image URLs
const imageUrls = [
"https://konvajs.org/assets/yoda.jpg",
"https://konvajs.org/assets/darth-vader.jpg",
];
// Reactive current URL
const currentUrl = ref(imageUrls[0]);
// useImage hook: Reactively use currentUrl
const [currentImage] = useImage(currentUrl);
// Toggle Image Function
const toggleImage = () => {
currentUrl.value =
currentUrl.value === imageUrls[0] ? imageUrls[1] : imageUrls[0];
};
</script> You can also get url as property of a component. https://codesandbox.io/p/sandbox/vue3-forked-zkfk4n?file=%2Fsrc%2FApp.vue%3A10%2C17 |
Yep, my bad, I was passing ref.value instead of ref. To avoid importing it everywhere in nuxt, I created export { useImage } from 'vue-konva' |
I just released a new version with a little
useImage
hook. Usage:If you read this, and interested in
vue-konva
. Try it. Let me know how it works for you.The text was updated successfully, but these errors were encountered: