[2.0] Templates for functional components
See original GitHub issueI’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>
Issue Analytics
- State:
- Created 7 years ago
- Reactions:54
- Comments:34 (11 by maintainers)
Top Results From Across the Web
Components and Props - React
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to...
Read more >Vue.js functional components: what, why, and when? - Medium
Functional components (not to be confused with Vue's render functions) is a component which holds no state and no instance. In more plain ......
Read more >Dealing with templates in Vue.js 2.0 - Sebastian De Deyne
The simplest way to define a component's template is by defining it in the template option. ... In JavaScript, strings aren't allowed to...
Read more >react-templates-components - npm
Simple template based React Components. Latest version: 2.2.8, last published: 2 years ago. Start using react-templates-components in your ...
Read more >Render Functions & JSX | Vue.js
Vue recommends using templates to build applications in the vast majority of cases. ... If a render function component doesn't need any instance...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is coming soon.
Yes, Vue 2.5 + vue-loader 13.3 will have proper support for template compilation, scoped CSS and hot-reload for functional components 😃