JuniorTour / vue-template-babel-compiler

Enable Optional Chaining(?.), Nullish Coalescing(??) and many new ES syntax for Vue.js SFC based on Babel
https://www.npmjs.com/package/vue-template-babel-compiler
118 stars 9 forks source link

[Fixed Bug] argument undefined in function call of scoped slot #2

Open csechuan opened 2 years ago

csechuan commented 2 years ago

Facing some issue when running this compiler in Nuxt. Trying to call a function on click of a component, but unable to retrieve the argument.

<component @click.prevent(greet('hello'))>

methods: { greet(message) { console.log(message) // return undefined } }

JuniorTour commented 2 years ago

As far as I konw,

First, you should use click listener with ="method", just like below, according to vue.js Document

  <div @click.prevent="greet('hello')">worked</div>

Then it will work as you expect, get your param: 0PYR) R)Q{BZYKVSFB5SQ1Y

Second, if you are using event listener of component, the usage is different, please refre to Listening to Child Components Events

Hope my reply is helpeful, Thank you for your feedback~

csechuan commented 2 years ago

I am using bootstrap-vue table. It behaves weirdly if i use this compiler.

<b-table :items="items">
  <template #cell(more)="{ item }">
    <b-button @click.prevent="greet(item)">test</b-button>  <!-- item is undefined -->
    <b-link :to="getLink(item)"></b-link> <!-- item is NOT undefined and has values -->
  </template>
</b-table>

But when i run the above code without this compiler, it just works fine.

JuniorTour commented 2 years ago

@csechuan It is a bug, I've published a new version 1.0.1 to fix.

You can try it by:

npm install vue-template-babel-compiler@1.0.1 -D
// or yarn
yarn add vue-template-babel-compiler@1.0.1 -D

U{3IWFA3A~WP84Y8YL @{YA

Thank you for your feedback!