Giter Club home page Giter Club logo

Comments (8)

PatrykWalach avatar PatrykWalach commented on April 29, 2024 1

h won't be inserted if you use an arrow function, so you can do

import {
  createComponent,
  createElement
} from 'vue-function-api'

export default createComponent({
  setup: props => {
    const h = createElement

    return () => {
      return (
        <div>card</div>
      )
    }
  }

from composition-api.

posva avatar posva commented on April 29, 2024

Could you open an issue there instead please? You probably don't need to use that plugin

from composition-api.

u3u avatar u3u commented on April 29, 2024

In order to be compatible with the old code, I may have to use this plugin. 😅

https://github.com/vuejs/vue-function-api/blob/a7413ec53021887c90f777c29a88e5c04cff8329/src/install.ts#L45-L52

Can we import createElement here and build a { $createElement: createElement } object to bind it to this? This may cause this in setup() to be not the expected undefined, but it will save a lot of trouble.

Now only need:

import { createComponent } from 'vue-function-api';

// No longer need to manually import `createElement as h`
// import { createComponent, createElement as h } from 'vue-function-api';

export default createComponent({
  setup(initialProps) {
    // babel plugin will auto-inject h
    // const h = this.$createElement;
    return (props) => <div>{props.msg}</div>;
  },
});

Is there any good solution?
Please consider reopening this issue. 🙏

from composition-api.

posva avatar posva commented on April 29, 2024

I would say that the fix is skipping the plugin at https://github.com/vuejs/jsx/blob/dev/packages/babel-sugar-inject-h/src/index.js#L60-L62 if we are in a setup function but I'm not sure. You could give it a try and directly create a PR to the plugin 🙂

We cannot add that hack as the lib must stay in sync with the RFC.

from composition-api.

u3u avatar u3u commented on April 29, 2024

Hum... I also considered this, but this plugin should eventually solve this problem.

If the plugin imports createElement from vue-function-api to auto-inject h is it appropriate? Will the createElement function be exposed directly in future Vue?

from composition-api.

u3u avatar u3u commented on April 29, 2024

@PatrykWalach As long as JSX is used in the function, h will be injected automatically. When I manually define const h = createElement there will be duplicate h identifier exceptions

from composition-api.

PatrykWalach avatar PatrykWalach commented on April 29, 2024

You won't get any errors using the method above. link
Exposing createElement is part of rfc#28 which changes the arguments of render function.

from composition-api.

u3u avatar u3u commented on April 29, 2024

@PatrykWalach Thank you! I didn't see it clearly before. 😂

from composition-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.