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

cannot get $refs.xxx for root dom #1311

Closed
tangjinzhou opened this issue Jun 7, 2020 · 4 comments
Closed

cannot get $refs.xxx for root dom #1311

tangjinzhou opened this issue Jun 7, 2020 · 4 comments

Comments

@tangjinzhou
Copy link
Contributor

tangjinzhou commented Jun 7, 2020

Version

3.0.0-beta.15

Reproduction link

https://jsbin.com/hayilijipi/edit?html,output

Steps to reproduce

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <script src="https://unpkg.com/vue@next"></script>

    <div id="app">
      <component-a> </component-a>
    </div>
    <script>
      const { ref, reactive, toRefs, createApp } = Vue;

      const componentB = {
        // inheritAttrs: false, // we can get $ref.root 
        // props: ["onClick"], // we can get $ref.root
        name: "component-b",
        template: "<slot></slot>" // we can not get $ref.root
        // template: '<div><slot></slot></div>' // we can get $refs.root
      };

      const componentA = {
        name: "component-a",
        components: { componentB },
        template: `
    <component-b @click="handleClick" ref="b">
      <div ref="root"><div ref="inner">hello</div></div>
    </component-b>
  `,
        methods: {
          handleClick() {
            console.log("handleClick");
          }
        },
        mounted() {
          console.log("this.$refs.b.$refs.root", this.$refs.b.$refs.root);
          console.log("this.$refs.root", this.$refs.root);
        }
      };

      let app = createApp({
        components: { componentB, componentA }
      });

      app.mount("#app");
    </script>
  </body>
</html>

What is expected?

get $refs.xxx

What is actually happening?

cannot get $refs.xxx

@underfin
Copy link
Member

underfin commented Jun 7, 2020

This can work in my local dev.I don't what happened with https://jsfiddle.net/8ctosfgu/31/.I get some error with blew image.It's unrelated and un-reproduction in my dev.
image

@liulinboyi
Copy link
Member

I think maybe this is the reason.
In VSCode, this SFC code, will prompt error.

image
image

@tangjinzhou
Copy link
Contributor Author

tangjinzhou commented Jun 8, 2020

Sorry. I closed this issue. In fact, the jsx I used should be the problem of the jsx plugin.

@tangjinzhou
Copy link
Contributor Author

@underfin I had to reopen this issue. I updated the code, I think it is a bug of vue3.

underfin added a commit to underfin/vue-next that referenced this issue Jun 15, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants