1

When I try to write SFC with <script setup> but without <template>, I get a warning in console [Vue warn] Component is missing template or render function.

Is there any workaround?

2 Answers 2

3

Vuejs dev answers, that one can use empty <template> in this case.

Sign up to request clarification or add additional context in comments.

Comments

1

Obviously, you need a Template or render function. Since you don't want to use template, You can consider using render function.

Unfortunately, the render function doesn't seem to work with setup.

<script lang="ts">
export default defineComponent({
  render() {
    return h("div", {}, this.a);
  }
});
</script>

<script lang="ts" setup>
import { defineComponent, ref, h } from "vue";

const a = ref(1);
</script>

<style scoped></style>

For more, you can see render-function(official doc) here.

3 Comments

I have several renderless components, so, its render functions are just () => null
@dmitriy-korobkov I have a question, if there is no render, why is it a component. If you must, try returning null in render function.
Renderless component is useful pattern in some cases. Now ought to returning () => null as render function in old fashion style.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.