Skip to content

Add jsx/tsx support #494

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

Closed
wants to merge 1 commit into from
Closed

Add jsx/tsx support #494

wants to merge 1 commit into from

Conversation

cereschen
Copy link

@cereschen cereschen commented Sep 1, 2020

Now if I write code like this:

new Vue({
  setup() {
    const count = ref(0);
    return () => (
      <div>
        <button onClick={() => count.value++}>the count is</button>
        {count.value}
      </div>
    );
  }
}).$mount("#app");

Will report this error

Error in data(): "TypeError: Cannot read property '$createElement' of undefined"

I checked the official plugin vuejs/jsx/babel-sugar-inject-h

          t.variableDeclaration('const', [
                t.variableDeclarator(
                  t.identifier('h'),
                  isRender
                    ? t.memberExpression(t.identifier('arguments'), t.numericLiteral(0), true)
                    : t.memberExpression(t.thisExpression(), t.identifier('$createElement')),
                ),
              ]),

Looks like we need the this prop $createElement

After fix, it won't affect the original function
Just pass a config when you use the plugin
Vue.use(compositionApi, { jsx: { enable: true} });

You can learn everything here
https://codesandbox.io/s/loving-sunset-m43pd?file=/src/main.js

@pikax
Copy link
Member

pikax commented Sep 2, 2020

Thank you, but this should be able handled by the jsx plugin.

Closing this is favour of vuejs/jsx-vue2#142

@pikax pikax closed this Sep 2, 2020
@cereschen
Copy link
Author

Thank you, but this should be able handled by the jsx plugin.

Closing this is favour of vuejs/jsx#142

That plan is better. I hope to see the change soon

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.

2 participants