Giter Club home page Giter Club logo

Comments (26)

nickmessing avatar nickmessing commented on May 2, 2024 33

@rhyek, @JsonSong89, @adamvleggett, @nddery, @zheeeng, @weivea, now you can use v-model in JSX if you add my v-model transform.

from babel-plugin-transform-vue-jsx.

nddery avatar nddery commented on May 2, 2024 7

You'll have to implement this yourself, as it is not available in render functions.

export default {
  data () {
    return {
      message: 'Salut'
    }
  },

  methods: {
    sync (prop, value) {
      this[prop] = value
    }
  },

  render (h) {
    return (
      <div>
        <input on-input={(e) => this.sync('message', e.target.value)} />
        <p>Message: {this.message}</p>
      </div>
    )
  }
}

See https://vuejs.org/v2/guide/render-function.html#v-model

from babel-plugin-transform-vue-jsx.

yyx990803 avatar yyx990803 commented on May 2, 2024 6

I think it should be a separate transform. v-model handles a lot of DOM-specific complexity and it should not be part of this transform (which is only about JSX to render-function conversion).

from babel-plugin-transform-vue-jsx.

nddery avatar nddery commented on May 2, 2024 2

@zheeeng for <select /> and <checkbox /> you can use on-change instead of on-input I think.

from babel-plugin-transform-vue-jsx.

adamvleggett avatar adamvleggett commented on May 2, 2024 2

From the perspective of a user of Vue, this specific abstraction is fundamental to being able to use JSX with Vue, and I doubt many (or any) developers will prefer it to be a separate transform. However if it really makes more sense to the maintainers of Vue, so be it.

Hopefully all of this can work with pug templates as well.

from babel-plugin-transform-vue-jsx.

zheeeng avatar zheeeng commented on May 2, 2024

@nddery This method doesn't work on <select />, <checkbox /> which you need to bind value on them first.

from babel-plugin-transform-vue-jsx.

JsonSong89 avatar JsonSong89 commented on May 2, 2024

v-model is a uniform way to bind value , if must bind in event, it'is really boring.

different element(and customer component) has different event .

from babel-plugin-transform-vue-jsx.

nickmessing avatar nickmessing commented on May 2, 2024

@178220709, if you want we can do a community effort to implement v-model in babel-plugin-transform-vue-jsx since it's an open-source project.

from babel-plugin-transform-vue-jsx.

adamvleggett avatar adamvleggett commented on May 2, 2024

Please do this. This is the only thing stopping me from switching all my Vue projects over to JSX, which I would much prefer to the proprietary .vue format.

from babel-plugin-transform-vue-jsx.

nickmessing avatar nickmessing commented on May 2, 2024

@adamvleggett, I am not sure @yyx990803 will accept model as a part of vue's official JSX transform. If he's okay I can make it as a part of vue-jsx (which makes sense because v-model is a very common pattern IMO). If not - I will make it a separate transform.

from babel-plugin-transform-vue-jsx.

nickmessing avatar nickmessing commented on May 2, 2024

@adamvleggett, how do you use pug templates with jsx? O_O

from babel-plugin-transform-vue-jsx.

adamvleggett avatar adamvleggett commented on May 2, 2024

https://www.npmjs.com/package/babel-plugin-react-pug

from babel-plugin-transform-vue-jsx.

yyx990803 avatar yyx990803 commented on May 2, 2024

@adamvleggett plugins should be focused on one thing only. What you want is a preset that includes thev-model transform by default.

from babel-plugin-transform-vue-jsx.

nickmessing avatar nickmessing commented on May 2, 2024

@adamvleggett, I though I am the only one who misses pug template language... I might have an idea about that. Let me do a POC over the week, I'll keep you up to date in this issue.

from babel-plugin-transform-vue-jsx.

adamvleggett avatar adamvleggett commented on May 2, 2024

Thanks. I appreciate it. It's not that I love pug, I just think having to close tags is a silly design.

from babel-plugin-transform-vue-jsx.

nickmessing avatar nickmessing commented on May 2, 2024

@yyx990803, this is not a good place to ask but I don't know any other, what do you think if some part of the community that still likes pug (like me and @adamvleggett) would maintain a "plugin" for vue-loader so syntax like:

<template plugin="pug">
  #user
    if user.description
      h2.green Description
      p.description= user.description
    else if authorised
      h2.blue Description
      p.description.
        User has no description,
        why not add one...
    else
      h2.red Description
      p.description User has no description
</template>
<script>
export default {
  data: () => ({
    user: { description: 'foo bar baz' },
    authorised: false
  })
}
</script>

Using pug as actual template language with vue? There is official plugin for pug to jsx which we can use as a starting ground. Is it a valid idea to make vue-loader support "plugins" for templates? If you accept I could do that.

from babel-plugin-transform-vue-jsx.

yyx990803 avatar yyx990803 commented on May 2, 2024

@nickmessing what prevents you from just using lang="pug"? It already works via pug-loader and you even have v-model with it.

from babel-plugin-transform-vue-jsx.

nickmessing avatar nickmessing commented on May 2, 2024

@yyx990803, yeah, but you can't use pug's conditionals, interpolation and all that stuff, you basically use pug as static to-html thing and then HTML result with vue's template language. Why not use pug as a complete template language instead (as it was designed to be in the first place)?

from babel-plugin-transform-vue-jsx.

yyx990803 avatar yyx990803 commented on May 2, 2024

@nickmessing well... then you'd have to re-invent everything in Vue's template syntax, or have a weird mix of both. Not sure about that, at least not something I'd be interested in.

from babel-plugin-transform-vue-jsx.

JsonSong89 avatar JsonSong89 commented on May 2, 2024

@nickmessing
jade (always like this name) has it's logic syntax and run in compile time ,
and vue also has it's syntax and run in browser runtime,
it is may confusing when we write them both together

from babel-plugin-transform-vue-jsx.

nickmessing avatar nickmessing commented on May 2, 2024

@JsonSong89, I was thinking of attempting to compile jade to render function and use it in <template> in vue-loader, I just like jade as a full template language for runtime

from babel-plugin-transform-vue-jsx.

JsonSong89 avatar JsonSong89 commented on May 2, 2024

@nickmessing oh , i get it, you mean write jade like jsx
it may is a huge projects,
jsx is a not only a syntax but also a standard ,
you need do compiler, syntax analyser, ide support .
after all ,it is not normal jade , it can use vue directive .

from babel-plugin-transform-vue-jsx.

rhyek avatar rhyek commented on May 2, 2024

Honestly, v-model in JSX would be insanely awesome. I much prefer using JSX to normal templates these days, but can't really commit to it due to the lack of this directive. It is just so practical and pleasant to use.

from babel-plugin-transform-vue-jsx.

rhyek avatar rhyek commented on May 2, 2024

Actually, being able to use all built-in and custom directives in JSX would just be crazy good.

from babel-plugin-transform-vue-jsx.

nickmessing avatar nickmessing commented on May 2, 2024

@rhyek, we can do that as community project, but check latest ssr changes, templates are way faster today, for pwa templates are much better

from babel-plugin-transform-vue-jsx.

ArmorDarks avatar ArmorDarks commented on May 2, 2024

@nickmessing

we can do that as community project, but check latest ssr changes, templates are way faster today, for pwa templates are much better

Can you be more specific about it? I just wonder how compiled with babel JSX is slower than compiled with loader templates? And there is an added complexity with SSR when using JSX, or I'm missing something?

from babel-plugin-transform-vue-jsx.

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.