-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed
Labels
Description
I'd like to be able to write templates and .vue
files for functional components the same way as standard components.
I made a proof-of-concept in this fiddle, but it's quite hacky. Maybe the template compiler could have a functional
option to make the resulting functions more adapted to the context
object and not this
.
It would look like this:
Vue.component('test', {
functional: true',
props: ['msg'],
template: `<div>
<h1>{{props.msg}}</h1>
<h2>Static content</h2>
<span v-for="n in 10">{{n}} </span>
<button @click="console.log('click', props.msg)"><slot></slot></button>
</div>`,
});
Or:
<template>
<div class="test">
<h1>{{props.msg}}</h1>
<h2>Static content</h2>
<span v-for="n in 10">{{n}} </span>
<button @click="console.log('click', props.msg)"><slot></slot></button>
</div>
</template>
<script>
export default {
functional: true,
props: ['msg'],
}
</script>
<style scoped>
.test {
margin: 12;
}
</style>
sebastiandedeyne, bobcolner, Ugzuzg, s130059660, carloscuatin and 39 morerayrutjes, nicolas-t, Samuell1 and ColeMortonmysticatea, rayrutjes, nicolas-t, Samuell1, ColeMorton and 1 more