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

fix(runtime-core): template ref should get exposed value from a top level await component. #4951

Closed
wants to merge 1 commit into from

Conversation

ygj6
Copy link
Member

@ygj6 ygj6 commented Nov 16, 2021

fix: #4930

@ygj6
Copy link
Member Author

ygj6 commented Nov 19, 2021

This PR could also solve the problem of the inline function mode of non-asynchronous components in the link: sfc.vuejs.org
If the non-asynchronous component directly calls the function, this inline mode will still have bugs:joy:. So I did not detect non-asynchronous scenes.

<template>
<button @click="showAtTop=!showAtTop">Toggle</button>
  <div v-if='showAtTop'>
    <!-- click and print null and input alternately, abnormal -->
    <input :ref='(value)=>{inputEl = value}'> 

    <!-- click and only print input, normal -->
    <!-- <input :ref='fn'>  -->
  </div>
  <hr>
  <div v-if='!showAtTop'>
    <!-- click and print null and input alternately, abnormal -->
    <input :ref='(value)=>{inputEl = value}'> 

    <!-- click and only print input, normal -->
    <!-- <input :ref='fn'>  -->
  </div>
</template>

<script setup lang='ts'>
import {ref,onMounted, onUpdated } from 'vue'
  const showAtTop = ref(false)
  const inputEl = ref(null)
  // const fn = (value)=>{inputEl.value = value}
  onMounted(()=>{
    console.log(inputEl.value)
  })
  
  onUpdated(()=>{
    console.log(inputEl.value)
  })

</script>

@LinusBorg
Copy link
Member

@edison1105 this PR is pretty outdated. Meanwhile, the whole templateRef logic has been moved into a separate file.

If @ygj6 is willing to update the PR, that would be great. Otherwise, we should do a fresh one.

@ygj6
Copy link
Member Author

ygj6 commented Dec 15, 2022

OK. Please do a new one.

@ygj6 ygj6 closed this Dec 15, 2022
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

Successfully merging this pull request may close these issues.

template ref can not get exposed value from a top level await component
2 participants