Open tcastelly opened 4 years ago
I've been thinking about this before, but now I'm going to show you a new way to write it in vue3
import {ref, withModifiers} from 'vue'
export default {
setup () {
const count =ref(0)
return ()=><div onClick={withModifiers(()=>count.value++,['stop'])}>{count.value} </div>
}
}
This way of writing will give you better IntelliSense and It is more compliant with the JSX specification
Here are all the supporting modifiers
Thank you! I did not know about this.
About the custom event with the problem definition type, do you have an idea? I tried this without success
declare namespace JSX {
interface IntrinsicElements {
MyCmp: {
onCustom: (str: string) => void,
},
}
...
}
<MyCmp
onCustom={(str) => console.log(str)} /> /* <-- TS2322: Type ... is not assignable to type */
interface IntrinsicElements available for Lower Camel Case components only. It wasn't easy but I found a way XD.
import { defineComponent } from "vue"
export function defineCustomComponent<P> (comp){
function defineCustom<T,K = T extends {new ():infer A}?A:never> (com:T):{new():K &{$props:P}}{
return com as any
}
return defineCustom(defineComponent(comp))
}
export default defineCustomComponent<{
onCustom: Function
}>({
setup(props, ctx) {
return () => <div> hello world! </div>
}
})
I will integrate it into my project
Sorry please do not use it. Too many bug.
No problem at all, thank you for your help :)
Hello,
Thank you very much for this plugin! I'm wondering if add a directive for custom event is possible.
It' works but it's not valid syntax. To be able to use kebab-case can be great:
Previously I used this plugin for jsx files, I really like to be able to stop propagation directly like this:
Do you think it's something can be imlemented?
Thank again for this plugin!