avatarShawn King

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

564

Abstract

ll as bread, places to play in and pray in, where nature may heal and give strength to body and soul. — John Muir</p></blockquote><p id="b84f"><b>To learn more about preserving our most precious resources, check out my guide on sustainable living:</b></p><div id="2b6f" class="link-block"> <a href="https://a-grace.medium.com/earth-in-crisis-1410528e10dc"> <div> <div> <h2>Plastic Earth: How to Reduce Our Impact</h2> <div><h3>The ocean is in crisis, as are many other environments. What can we do

Options

to help?</h3></div> <div><p>a-grace.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*gBsQ3BaEPAz5dZ27R-qkPw.jpeg)"></div> </div> </div> </a> </div><figure id="0019"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*9ZjQFr0V5dROCE6VbGJLug.jpeg"><figcaption>Image Credit: <a href="https://a-grace.medium.com/">A. Grace</a> (Aly Pictured It)</figcaption></figure></article></body>

Understanding Fragment in Vue3

Vue series of articles

I wonder if anyone has encountered the following error information in Vue2:

Errors compiling template:
Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.

This is an error prompt thrown by Vue2. It means that a component can only have one root element. When we create a new Vue page, there are usually multiple different element nodes. We will wrap a div at the outermost layer to make it the root node of this page. But this is not user-friendly. Sometimes we don’t need this div element.

Vue3 has solved this problem. Vue3 has introduced a new DOM-like tag element <Fragment></Fragment>. If there are multiple element nodes in the Vue page, Vue will add a <Fragment></Fragment> tag to these element nodes during compilation. And this tag does not appear in the DOM tree.

Example

<template>
 <header>...</header>
 <main v-bind="$attrs">...</main>
 <footer>...</footer>
</template>
Vuejs
Vue
JavaScript
Frontend
Coding
Recommended from ReadMedium