The Wayback Machine - https://web.archive.org/web/20200414172453/https://github.com/vuejs/jsx
Skip to content
monorepo for Babel / Vue JSX related packages
JavaScript
Branch: dev
Clone or download

Latest commit

dependabot chore(deps): bump acorn in /packages/babel-plugin-transform-vue-jsx (#…
…131)

Bumps [acorn](https://github.com/acornjs/acorn) from 6.0.4 to 6.4.1.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](acornjs/acorn@6.0.4...6.4.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Latest commit 7625197 Mar 21, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci ci: fix ci permission issues Feb 19, 2020
.vscode init May 28, 2018
packages chore(deps): bump acorn in /packages/babel-plugin-transform-vue-jsx (#… Mar 21, 2020
scripts
.gitignore init May 28, 2018
.prettierignore Add package.json to .prettierignore May 28, 2018
CHANGELOG.md chore: 1.1.2 changelog [ci skip] Feb 13, 2020
README.md docs: fix `vModel` & `vOn` code examples Aug 6, 2019
lerna.json v1.1.2 Nov 9, 2019
package.json chore: update lerna Feb 19, 2020
yarn.lock chore: update lerna Feb 19, 2020

README.md

Babel Preset JSX

Configurable Babel preset to add Vue JSX support. See the configuration options here.

Installation

Install the preset with:

npm install @vue/babel-preset-jsx @vue/babel-helper-vue-jsx-merge-props

Then add the preset to .babelrc:

{
  "presets": ["@vue/babel-preset-jsx"]
}

Syntax

Content

render() {
  return <p>hello</p>
}

with dynamic content:

render() {
  return <p>hello { this.message }</p>
}

when self-closing:

render() {
  return <input />
}

with a component:

import MyComponent from './my-component'

export default {
  render() {
    return <MyComponent>hello</MyComponent>
  },
}

Attributes/Props

render() {
  return <input type="email" />
}

with a dynamic binding:

render() {
  return <input
    type="email"
    placeholder={this.placeholderText}
  />
}

with the spread operator (object needs to be compatible with Vue Data Object):

render() {
  const inputAttrs = {
    type: 'email',
    placeholder: 'Enter your email'
  }

  return <input {...{ attrs: inputAttrs }} />
}

Slots

named slots:

render() {
  return (
    <MyComponent>
      <header slot="header">header</header>
      <footer slot="footer">footer</footer>
    </MyComponent>
  )
}

scoped slots:

render() {
  const scopedSlots = {
    header: () => <header>header</header>,
    footer: () => <footer>footer</footer>
  }

  return <MyComponent scopedSlots={scopedSlots} />
}

Directives

<input vModel={this.newTodoText} />

with a modifier:

<input vModel_trim={this.newTodoText} />

with an argument:

<input vOn:click={this.newTodoText} />

with an argument and modifiers:

<input vOn:click_stop_prevent={this.newTodoText} />

v-html:

<p domPropsInnerHTML={html} />

Functional Components

Transpiles arrow functions that return JSX into functional components, when they are either default exports:

export default ({ props }) => <p>hello {props.message}</p>

or PascalCase variable declarations:

const HelloWorld = ({ props }) => <p>hello {props.message}</p>

Compatibility

This repo is only compatible with:

You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.