travel/admin/node_modules/@vue/babel-sugar-v-on
yaosen 242417d45d init... 2024-06-24 11:28:18 +08:00
..
dist init... 2024-06-24 11:28:18 +08:00
node_modules/camelcase init... 2024-06-24 11:28:18 +08:00
README.md init... 2024-06-24 11:28:18 +08:00
package.json init... 2024-06-24 11:28:18 +08:00

README.md

@vue/babel-sugar-v-on

Syntactic sugar for v-on in JSX.

Babel Compatibility Notes

Usage

Install the dependencies:

# for yarn:
yarn add @vue/babel-sugar-v-on
# for npm:
npm install @vue/babel-sugar-v-on --save

In your .babelrc:

{
  "plugins": ["@vue/babel-sugar-v-on"]
}

However it is recommended to use the configurable preset instead.

Details

This plugin adds v-on to the JSX and tries to mirror the same behaviour as in vue-template-compiler, with a few differences:

  1. You should use underscore (_) instead of dot (.) for modifiers (vOn:click_prevent={this.test})
  2. It is recommended to use camelCase version of it (vOn) in JSX, but you can use kebab-case too (v-on).
export default {
  methods: {
    test() {
      console.log('Hello World')
    },
  },
  render(h) {
    return (
      <div>
        <a href="https://vuejs.org" vOn:click={this.test}>Vue</a>
      </div>
    )
  },
}