question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[2.0] Templates for functional components

See original GitHub issue

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>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:54
  • Comments:34 (11 by maintainers)

github_iconTop GitHub Comments

31reactions
Akryumcommented, Feb 5, 2017

It is coming soon.

16reactions
yyx990803commented, Oct 11, 2017

Yes, Vue 2.5 + vue-loader 13.3 will have proper support for template compilation, scoped CSS and hot-reload for functional components 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found