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

refs not working on custom component #113

Closed
TheDutchCoder opened this issue Dec 22, 2021 · 2 comments
Closed

refs not working on custom component #113

TheDutchCoder opened this issue Dec 22, 2021 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@TheDutchCoder
Copy link

TheDutchCoder commented Dec 22, 2021

When I extract meshes/groups into Vue components, I can't seem to be able to use refs on the custom component.

Example:

Thing.vue

<template>
  <Group>
    <Box>
      <LambertMaterial color="#222222" />
    </Box>
  </Group>
</template>

<script setup>
import { Group, Box } from 'troisjs'
</script>

App.vue

<template>
  <Renderer ref="rendererC" antialias :orbit-ctrl="{ enableDamping: true }" resize="window" shadow>
    <Camera ref="camera" :position="{ x: 10, y: 10, z: 10 }" />
    <Scene>
      <Thing ref="thing" />
    </Scene>
  </Renderer>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { Renderer, Camera, Scene } from 'troisjs'

import Thing from './components/thing.vue'

const thing = ref()

onMounted(() => {
  console.log(thing.value) // This seems to be a complete empty ref with a `__v_skip` attribute
})
</script>
@RingoKam
Copy link

Yup ran into the same issue as well

@klevron klevron self-assigned this Jan 4, 2022
@klevron klevron added this to the 0.3.4 milestone Jan 4, 2022
@klevron
Copy link
Member

klevron commented Feb 16, 2022

You should try :

Thing.vue

<template>
  <Group>
    <Box ref="box">
      <BasicMaterial color="#222222" />
    </Box>
  </Group>
</template>

<script setup>
import { ref } from 'vue'
import { Group, Box, BasicMaterial } from 'troisjs'

const box = ref()

defineExpose({ box })
</script>

App.vue

onMounted(() => {
  console.log(thing.value.box)
})

https://vuejs.org/api/sfc-script-setup.html#defineexpose

@klevron klevron added the documentation Improvements or additions to documentation label Feb 16, 2022
@klevron klevron closed this as completed Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants